【发布时间】:2017-06-27 07:40:17
【问题描述】:
我在我的主题中创建了我的第一个自定义简码,在 functions.php 中添加了以下几行
function ec_toggle_content($atts, $content = null){
$togtit='Title test';
extract(shortcode_atts(array('togtit'=> ''), $atts));
$output .= '<h4 class="toggletrg">'.$title.' <i class="fa fa-plus right toggleicon"></i><i class="fa fa-minus right toggleicon hidden"></i></h4>';
$output .= '<div class="togglecont">';
$output .= do_shortcode($content);
$output .= '</div>';
return $output;
add_shortcode('toggle', 'ec_toggle_content');
}
当我编辑我的一篇帖子时添加短代码,即
[toggle togtit="comn pleas work"]bla bla bla text[/toggle]
它只是呈现为纯文本...(供参考,http://ipfcommunity.wdemo.it/aggiornamenti/news/respirare-sottacqua-piccoli-esercizi-sopravvivenza-spirituale/)
我真的不知道如何让它工作,我读到最常见的问题可能是我没有使用 get_content() 来检索帖子内容,但这就是我所做的,所以我可以'找不到任何进一步的建议。
【问题讨论】:
-
ehm,你确定
add_shortcode('toggle', 'ec_toggle_content')应该在函数内部并且在 return 语句之后? -
我遵循了这个指南mosaikweb.com/toggle-plus-shortcode,这是我第一次发现自己模板化简码
-
@FMashiro 我按照您的提示进行操作,如果您想发布答案,我很乐意将其标记为正确。谢谢。
-
没关系,把你自己的标记为接受:)
标签: php wordpress wordpress-theming shortcode