如何在wordpress theme中使用short code

在 wordpress 的 theme 中, 若想使用一些原本在 page 或 post 中的外掛 shortcode , 要如何使用呢?

只需要在 theme 的程式碼中使用 do_shortcode 函式即可, 如下:
[code]
echo do_shortcode(“[example_shortcode]”);
[/code]

如此一來便能在 wordpress theme 中使用 shortcode 了.

參考資料:

http://www.wpbeginner.com/wp-themes/how-to-use-shortcodes-in-your-wordpress-themes/

http://www.wpbeginner.com/wp-tutorials/how-to-add-a-shortcode-in-wordpress/

wordpress escape shortcode的方法

基本上在 wordpress 中, 有個特殊的功能, 就是 shortcode, 可以利用這個功能來將文章的內容替代, 如同前一篇文章中的 video code plugin:

http://tim.diary.tw/2013/05/24/install-wordpress-plugin-video-codes/

由於在上一篇文章中, 會介紹該 shortcode 的用法, 所以就要列出 shortcode 語法出來, 有意思的地方是直接打該 shortcode 就會使文章呈現的結果套用對應的 shortcode, 所以需要 escape (跳脫)掉這個 shortcode.

在 html 要 escape 可以直接使用 & # 91 ;  及 & # 93 ;  替代 shortcode 的前後中括號 (記得是在 html source 編輯下輸入), 這樣的方式就可以讓該 shortcode 不會發生作用, 如此一來也就可以在文章中使用 shortcode 代碼介紹, 但不會發生作用.

參考文章:

http://wordpress.org/support/topic/escaping-shortcode