Wordpress Shortcode"内容"不工作

时间:2017-12-12 14:51:39

标签: php wordpress shortcode

我尝试在Wordpress中注册一个短代码。为了以更简单的方式显示问题,我使用此代码:

 function moewe_readmore($atts, $content = null) {
  extract(shortcode_atts(array(
    'posts' => 1,
    'class' => '',
   ), $atts));

   $return_string = '<h4>'.$content.'</h4>';
   return $return_string;

 }

 add_shortcode('mrm', 'moewe_readmore');

我将这个短代码添加到我的主题:

<?php echo do_shortcode("[mrm]I am the Headline[mrm]"); ?>

但是输出空了&#34;&lt; h4&gt;&#34;元素和标题单独放在没有html标记。

谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

它看起来不像$ content会包含任何东西,它当前设置为null。我还要将“我是标题”一文分开。

function moewe_readmore($atts, $content = null) {
    extract(shortcode_atts(array(
        'posts' => 1,
        'class' => '',
    ), $atts));

    $return_string = '<h4>'.$content.'</h4>';
    return $return_string;
}
add_shortcode('mrm', 'moewe_readmore');

然后你可以使用这个: <?php echo do_shortcode("[mrm]"); ?> I am the headline

相关问题