dongshanfan1941 2015-05-12 14:04
浏览 9

无法在功能中获取短代码内容

I use a shortcode on my page like

[abc a="b"]test[/abc]

In my functions.php

add_shortcode('abc', function($atts, $content) {
    return $atts['a']." : ".$content;
});

And in my template somewhere

<p><?php echo do_shortcode('[abc]') ?></p>

$atts, $content are always empty.

Everything works fine in the Default template but not in mine.

I really appreciate if anyone can show me how to get it work in my custom template. Thanks

  • 写回答

2条回答 默认 最新

  • dongwei2030 2015-05-12 14:32
    关注

    You should add these line of code in your custom page template , it will automatically apply filters on content like wpautop and other shortcodes

    <?php if(have_posts()) : ?>
    <?php while(have_posts()) : the_post() ?>
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php endwhile; else : ?>
    <?php endif; ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)