2015-04-01 43 views
0

我想發佈短代碼的自定義帖子類型有功能添加新聞,但它只是繼續顯示短代碼本身,而不是短代碼內容。WordPress的短代碼在自定義帖子類型

在我的主題的functions.php的我已經加入:

add_filter('insertPages_init', 'shortcode_unautop'); 
add_filter('insertPages_init', 'do_shortcode'); 

,並在我的insertpages插件的功能如下:

function insertPages_init() { 
    add_shortcode('insert', array($this, 'insertPages_handleShortcode_insert')); 
} 

從自定義類型後製作後仍然只是打印短代碼而不是其內容。我可以得到它的工作,因爲我希望使用示例:

add_filter('widget_text', 'do_shortcode'); 

而且工作得很好。

如何讓我的自定義帖子類型接受簡碼?

+0

嘗試調用'init'鉤子上的'insertPages_init'。 – SidFerreira 2015-04-01 09:15:24

+0

https://wordpress.org/support/topic/enable-shortcodes-in-custom-post-types – bodi0 2015-04-01 09:16:49

+0

嗨,對不起,即時通訊新的,我將如何去呢?謝謝 – darrrrUC 2015-04-01 09:17:09

回答

0

我覺得insertPages_init過濾器的問題,增加了短代碼的一般形式是:

function footag_func($atts) { 
    return "foo = {$atts['foo']}"; 
} 
add_shortcode('footag', 'footag_func'); 

,如果你想在喜歡初始化動作加載:

add_action('init', 'load_footag_shortcode'); 

function footag_func($atts) { 
    return "foo = {$atts['foo']}"; 
} 

function load_footag_shortcode(){ 
add_shortcode('footag', 'footag_func'); 
} 
相關問題