wordpress - 在 WordPress 主题中启用短代码

标签 wordpress themes

我从头开始为 WordPress 3.3.1 开发了一个新主题,但短代码不起作用。 正如我到目前为止所搜索的那样,这是过滤包含短代码的内容的问题,过滤器代码添加在主题特定位置(短代码正在与另一个主题一起使用)。 所以,我的问题是:启用通用短代码主题的代码是什么?

最佳答案

要执行单个短代码,请使用

运行它
echo do_shortcode('[your_short_code]');

如果短代码位于帖子内容中,请确保使用以下方式显示它

<?php the_content();?>

或者

<?php echo apply_filters('the_content',$post_content);?>

或者

<?php echo apply_filters('the_content',$wp_query->post->post_content);?>

重要的是:如果您不使用函数“the_content()”,则需要此行 <?php echo apply_filters('the_content',$wp_query->post->post_content);?>在第二个参数中,您必须放置要显示的帖子内容的变量。

关于wordpress - 在 WordPress 主题中启用短代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9820190/

相关文章:

.net - 获取 Windows 主题?

php - 从 Wordpress 中的 style.css 文件获取主题信息

html - 插入更多文本时 DIV 不会变宽

php - 用 PHP 替换图像标签周围的链接

javascript - 在 jQuery 中切换 wordpress 中的事件和非事件 div

excel - OfficeJs - 获取 excel/powerpoint 文件的字体/主题颜色

css - Drupal - Apache 的 Mod_Deflate 破坏了 CSS

php - 如何在 Wordpress 中制作最近的帖子轮播

php - 根据在 WooCommerce 结帐中进行验证的选择字段显示/隐藏自定义字段

css - Wordpress 菜单不会保持在顶部