• Resolved mrhardwer

    (@mrhardwer)


    Hey there,

    I’m working on a new Worpdress-Theme and I’m currently stuck with the Theme Customization API. I’m not really new to WordPress/Coding but never had anything to do with the API. So I watched some totorials and readed some posts about that whole thing and started including it into my Theme. Sofar everything went well. But now for some reason, my new sections I wrote into my functions.php are not showing up in the Theme Customasation API. I allredy tryed to remove some parts but nothing has changed. Is there anything wrong with my code? Or is it something different?

    Here’s my functions.php code:

    function tonya_customizer_register($wp_customize) {
    	$wp_customize->add_section('tonya_colors', array(
    		'title' => __('Colors', 'tonya'),
    		'description' => 'Modify the theme colors'
    	));
    
    	// Background Color
    	$wp_customize->add_setting('background_color', array(
    		'default' => '#fff',
    	));
    		$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'background_color', array(
    		'label' => __('Edit Background Color','tonya'),
    		'section' => 'tonya_colors',
    		'settings' => 'background_color',
    	) ));
    
    	// Plain Text
    	$wp_customize->add_setting('plain_text', array(
    		'default' => 'test',
    	));
    	$wp_customize->add_control( new WP_Customize_Control($wp_customize, 'plain_text', array(
    		'label' => __('Edit Plain Text','tonya'),
    		'section' => 'tonya_colors',
    		'settings' => 'plain_text',
    	) ));
    
    	// Upload Image
    	$wp_customize->add_setting('upload_image', array(
    		'default' => 'test',
    	));
    	$wp_customize->add_control( new WP_Customize_Upload_Control($wp_customize, 'upload_image', array(
    		'label' => __('Edit Uplaod Image','tonya'),
    		'section' => 'tonya_colors',
    		'settings' => 'upload_image',
    	) ));
    
    	// Checkbox
    	$wp_customize->add_section('tonya_checkbox', array(
    		'title' => __('Layout Options', 'tonya'),
    		'description' => 'Modify the layout'
    	));
    	$wp_customize->add_setting('checkbox_setting', array(
    		'default' => 'left',
    	));
    	$wp_customize->add_control( 'checkbox_select', array(
    		'label' => __('Checkbox One','tonya'),
    		'section' => 'tonya_checkbox',
    		'settings' => 'checkbox_setting',
    		'type' => 'checkbox',
    		'choices' => array(
    			'left' => 'Right Checkbox',
    			'right' => 'Left Checkbox',
    		)
    	));
    }
    
    function tonya_css_customizer() {
    	?>
    	<style type="text/css">
    		body { background-color: #<?php echo get_theme_mod('background_color'); ?>; }
    	</style>
    	<?php
    }
    
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Did you add your action(s)?
    add_action('customize_register','tonya_customizer_register');

    Tell me and i’ll get back to you.

    SYA ??

    Thread Starter mrhardwer

    (@mrhardwer)

    Hey LebCit,

    First off thank you for the quick and helpfull rely.
    After I copyed the add_action above the first function (tonya_customizer_register), the sections with the settings are now showing in the Theme Customization API. Now I see that the changes I make (background-color) are not working. Might I need another action for my second function (tonya_css_customizer)? Or do I need to paste the code somewere else?

    Hello,

    Great! the add_action can be placed before or after the function, so you’ve done well.

    For the css try this

    function tonya_css_customizer() {
    	$background_color = get_theme_mod( 'background_color' ); 
    	
    	if ( $background_color != '#fff' ) :
    	?>
    		<style type="text/css">
    			body {
    				background-color: <?php echo $background_color; ?>;
    			}
    		</style>
    	<?php
    	endif;
    }
    add_action( 'wp_head', 'tonya_css_customizer' );

    Tell me if i can help you further.

    SYA ??

    • This reply was modified 8 years, 4 months ago by LebCit.
    Thread Starter mrhardwer

    (@mrhardwer)

    Hey LebCit,

    I looked at one of the totorial videos once again and I saw that the 2 actions (customize_register and wp_head) were allredy included. I somehow deleted these 2 lines of code without noticing it.

    For information: I now included both codes

    add_action('wp_head','tonya_css_customizer');
    add_action('customize_register','tonya_customizer_register');

    under the 2 functions in my functions.php and now everything works as it should do.

    But still thank you LebCit for putting me on the right way!

    • This reply was modified 8 years, 4 months ago by mrhardwer.

    Hello,

    You are most welcome
    Did you notice my first question

    Did you add your action(s)?

    See the (s) ??

    I thought that you did it for the style (my fault)

    Again, you are most welcome !
    Happy codding !

    SYA ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Theme Customization API now showing’ is closed to new replies.