簡體   English   中英

如何為管理員主題選項創建簡碼-Wordpress

[英]How to create a shortcode for Admin Theme Option - Wordpress

我正在嘗試為我的主題的兩個選項創建一個簡碼。 基本上,我想將我的主題選項保存到我的短代碼中,以便可以在帖子的任何位置顯示它們,如下所示:

[ads_1] 
[ads_2]

但是,當我嘗試在簡碼中獲取選項時,它將根本無法工作,並且給我一個錯誤

解析錯誤:語法錯誤,第86行的C:\\ xampp \\ htdocs \\ themewp \\ wp-content \\ themes \\ bots_final \\ shortcodes.php中出現意外的'theme_settings'(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>

知道為什么我不能抓住它是什么問題嗎?

您在打開的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'您的設置存儲為'mytheme_theme_settings'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM