我正在嘗試顯示來自自定義輸入的文本,但徒勞無功。我正在為我的網站開發一個自定義 WordPress 主題。我已將該欄位添加到 Wordpress 定制器,但該欄位的內容未顯示在頁面上。
function prolifictheme_add_customizer_content( $wp_customize ) {
$wp_customize->add_section( 'prolific_theme_text_setting_id', array(
'title' => __( 'General Settings', 'prolific-theme' ),
'priority' => 30,
'description' => __( 'Customize the layout of your site homepage', 'prolific-theme' )
) );
$wp_customize->add_setting( 'prolific_theme_text_setting_id', array(
'capability' => 'edit_theme_options',
'default' => 'Text Goes Here',
'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control( 'prolific_theme_text_setting_id', array(
'type' => 'text',
'section' => 'prolific_theme_text_setting_id', // Add a default or your own section
'label' => __( 'Main Banner Title' ),
'description' => __( 'Enter title of not more than 35 Words.' ),
) );
}
add_action( 'customize_register', 'prolifictheme_add_customizer_content' );
顯示文本
<h1><?php echo get_theme_mod( 'prolific_theme_text_setting_id' ); ?></h1>
uj5u.com熱心網友回復:
您的代碼開箱即用。你把文字放在哪里了?將其插入底部,header.php您將看到它。我認為您在錯誤的模板中搜索結果。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/475534.html
標籤:WordPress
