do_shortcode在my index.php上不起作用
我在functions.php上注册了一个短代码do_shortcode在my index.php上不起作用,php,wordpress,shortcode,Php,Wordpress,Shortcode,我在functions.php上注册了一个短代码 function offer_intro_shortcode ($atts, $content=null) { $offer = shortcode_atts( array ( 'title' => '', 'text' => '', ), $atts ); extract ($offer); return '<div class="center gap">
function offer_intro_shortcode ($atts, $content=null) {
$offer = shortcode_atts( array (
'title' => '',
'text' => '',
), $atts );
extract ($offer);
return '<div class="center gap">
<h3>'.$title.'</h3>
<p class="lead">'.$text.'</p>
</div>';
}
add_shortcode ('offer', 'offer_intro_shortcode');
然后我在index.php上查询这个短代码,就像do_短代码(“[offer]”)一样
但它不起作用试试这个
echo do_shortcode("[offer title='What We Offer' text='Look at some of the recent projects we have completed for our valuble clients']");
检查此功能是否正常。在$atts之后添加另一个参数,即shortcode,使其变为
$offer = shortcode_atts( array (
'title' => '',
'text' => '',
), $atts,'offer' );
它正在工作,但我想从我的wordpress目录中控制它你想写add_shortcode('offer','offer_intro_shortcode');在你的index.php文件中,对吗?我在wordpress的一篇帖子上写了[offer title='What We offer'text='Look of the我们最近为有价值的客户完成的一些项目]。我想通过do_shortcode(“[offer]”)来查询它,我想在这里显示它。当我这样做的时候,index.php得到的是样式,而不是内容嘿,我很困惑,请澄清你想显示什么。标题和文本我在wordpress Post上写的内容你能澄清一下“不工作”是什么意思吗?(旁白:“有价值的客户”应该是“有价值的客户”)。这是拼写错误。我通过写do_shortcode(“[offer]”)来查询短代码。。但它并没有显示我在帖子中所写的内容,[提供标题=“我们提供的”文本=“看看我们最近为我们的重要客户完成的一些项目”]
$offer = shortcode_atts( array (
'title' => '',
'text' => '',
), $atts,'offer' );