我正在尝试为我的2个主题选项创建一个短代码。基本上我想把我的主题选项放到我的短代码中,以便我可以在我的帖子上的任何地方显示它们:
[ads_1]
[ads_2]
然而,当我试图在我的短代码上获得选项时,它根本不起作用并且它给我一个错误
解析错误:语法错误,意外' theme_settings'第86行的C:\ xampp \ htdocs \ themewp \ wp-content \ themes \ bots_final \ shortcodes.php中的(T_STRING)
这是我的短代码片段,我在尝试抓取我的主题选项数据:
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>
知道为什么我无法抓住它的问题是什么?
答案 0 :(得分:0)
您在打开的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'
。