2016-08-17 7 views
0

私はWordPressのテーマに取り組んでいますが、これはどのように動作するかを見ていますが、今ではいくつかのカスタム設定/コントロールを実装したいと思っています。だからここに私は#fffのような実際の色とラインecho get_theme_mod('background_color');を変更するときに、それが正常に動作します私はwordpressのカスタマイザget_theme_modは出力しない

function myfirsttheme_customizer_register($wp_customize){ 
     $wp_customize->add_section('mycustomtheme_colors', array(
     'title' => __('Colors','mycustomtheme'), 
     'description' => 'Modify the theme colors' 
     )); 

     $wp_customize->add_setting('background_color', array(
     'default' => '#fff', 
     )); 

     $wp_customize->add_setting('link_color', array(
     'default' => '#4b4b4', 
     )); 

     $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'background_color', array(
     'label' => __('Edit Background Color', 'mycustomtheme'), 
     'section' => 'mycustomtheme_colors', 
     'settings' => 'background_color' 
     ))); 

     $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'link-color', array(
     'label' => __('Edit Link Color', 'mycustomtheme'), 
     'section' => 'mycustomtheme_colors', 
     'settings' => 'link_color' 
     ))); 
    } 
add_action('wp_head','mycustomtheme_css_customizer'); 
add_action('customize_register','myfirsttheme_customizer_register'); 

とHTML/CSSここ

function mycustomtheme_css_customizer(){ 
    ?> 

    <style type="text/css"> 
     article { background-color:<?php echo get_theme_mod('background_color');?> ; } 
    </style> 

    <?php 
} 

を試みたものですが、いくつかの理由でget_theme_mod doesnの出力を与えると私はなぜ理解できないのですか?

+0

チェックをうまくいくあなたの設定配列にこれらの行を追加します。このhttp://wordpress.stackexchange.com/questions/90942/issue-with -get-theme-mod-returning-a-blank-value-saved-of-the-saved-value –

答えて

0

'type' => 'theme_mod', 'capability' => 'edit_theme_options',

は、次のコードは、

function myfirsttheme_customizer_register($wp_customize){ 
    $wp_customize->add_section('mycustomtheme_colors', array(
    'title' => __('Colors','mycustomtheme'), 
    'description' => 'Modify the theme colors' 
    )); 

    $wp_customize->add_setting('background_color', array(
    'default' => '#fff', 
    'type' => 'theme_mod', 
    'capability' => 'edit_theme_options' 
    )); 

    $wp_customize->add_setting('link_color', array(
    'default' => '#4b4b4', 
    'type' => 'theme_mod', 
    'capability' => 'edit_theme_options' 
    )); 

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'background_color', array(
    'label' => __('Edit Background Color', 'mycustomtheme'), 
    'section' => 'mycustomtheme_colors', 
    'settings' => 'background_color' 
    ))); 

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'link-color', array(
    'label' => __('Edit Link Color', 'mycustomtheme'), 
    'section' => 'mycustomtheme_colors', 
    'settings' => 'link_color' 
    ))); 
} 

add_action('customize_register','myfirsttheme_customizer_register'); 
+0

コードをコピー&ペーストしましたが、まだ動作しません。/ –

関連する問題