我正试图为我的主题的选项2创建一个短代码。基本上,我想把我的主题选项抓取到我的短代码,这样我就可以在我的帖子的任何地方显示它们,像这样:
[ads_1]
[ads_2]
然而,当我试图得到我的短代码的选项,它不会工作,它给我一个错误
解析错误:语法错误,意想不到的'theme_settings' (T_STRING)在C:'xampp'htdocs'themewp'wp-content'themes'bots_final'shortcodes.php第86行
这是我的短代码片段,在我试图抓住我的主题选项数据:
add_shortcode('ads_1', function($atts){
return '
<div>
<?php $options = get_option( 'theme_settings' ); ?>
<?php echo $options['banner1']; ?>
</div>';
});
我正试图从我的主题选项页抓取选项。检查主题选项代码:
<div>
<?php $options = get_option( 'theme_settings' ); ?>
<?php echo $options['banner1']; ?>
</div>
知道是什么问题,为什么我拿不到它吗?
您在打开的php标签中打开了<?php
:
add_shortcode('ads_1', function($atts){
$html = '<div>';
$options = get_option( 'theme_settings' );
$html .= $options['banner1'];
$html .= '</div>';
return $html;
});
你从get_option( 'theme_settings' );
得到什么?看起来你是在建议一个数组…为了避免冲突,我将您的设置存储为'mytheme_theme_settings'
。