【问题标题】:Wordpress shortcode doesn't renderWordpress 短代码不呈现
【发布时间】: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


【解决方案1】:

以下指南具有误导性mosaikweb.com/toggle-plus-shortcode

基本上按照 FMashiro 的暗示,我搬家了

add_shortcode('toggle', 'ec_toggle_content');

在我的示例代码的顶部,工作结果是

add_shortcode('toggle', 'ec_toggle_content');

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;

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-28
    • 2018-08-15
    • 2021-01-16
    • 1970-01-01
    • 2018-05-06
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多