在 wordpress 主题中启用短代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9820190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Enable shortcodes in a wordpress theme
提问by Nistor Teodora
I develop a new theme for wordpress 3.3.1 from scratch and shortcodes are not working on it. As I searched until now it is a matter of filtering the content containing the shortcode, filter code added in a theme specific location(shorcodes are working with another theme). So, my question is : What is the code for a general shortcode theme enable ?
我从头开始为 wordpress 3.3.1 开发了一个新主题,但短代码不起作用。到目前为止,我一直在搜索包含短代码的内容,过滤器代码添加到主题特定位置(短代码正在与另一个主题一起使用)。所以,我的问题是:一般短代码主题启用的代码是什么?
回答by alesub
To execute a single shortcode, run it with
要执行单个短代码,请运行它
echo do_shortcode('[your_short_code]');
If the shortcode(s) are in the post content, make sure you're displaying it with
如果短代码在帖子内容中,请确保您正在显示它
<?php the_content();?>
Or
或者
<?php echo apply_filters('the_content',$post_content);?>
Or
或者
<?php echo apply_filters('the_content',$wp_query->post->post_content);?>
The important thing is: if you aren't using the function "the_content()" you need this line <?php echo apply_filters('the_content',$wp_query->post->post_content);?>
where in the second argument you have to put the variable of the post content you want to show.
重要的是:如果您不使用函数“the_content()”,您需要<?php echo apply_filters('the_content',$wp_query->post->post_content);?>
在第二个参数中放置要显示的帖子内容的变量的这一行。
回答by BuddyLove
I had to save the theme's content to a variable and then use the second example.. Worked like a charm.
我不得不将主题的内容保存到一个变量,然后使用第二个示例.. 就像一个魅力。
$mycontent = ot_get_option('rightcontent');
echo apply_filters('the_content',$mycontent);