Link to home
Start Free TrialLog in
Avatar of axessJosh
axessJosh

asked on

WP Customizer - Section Settings to Front End

Not sure how to phrase the question exactly but I am working on adding custom items to the theme customizer in Wordpress.

I have added a Section for the user to add Social Media Accounts and have a linked image show if content exists.  Here is my code in my functions file.

// add Social Media Selction section
	$wp_customize->add_section( 'parallaxone_social_options_section' , array(
		'title'      => __( 'Social Media Options', 'parallaxone' ),
		'priority'   => 150,
	) );	
	// add setting to select facebook
	$wp_customize->add_setting( 'parallaxone_facebook_select', array( 
		'fbdefault' 	=> ' '
	) );
		$wp_customize->add_control( 'parallaxone_facebook_select', array(
		'label'     => __( 'Facebook', 'parallaxone' ),
		'section'   => 'parallaxone_social_options_section',
		'priority'  => 10,
		'type'      => 'text'
	) );
	
	// add setting to select twitter
	$wp_customize->add_setting( 'parallaxone_twitter_select', array( 
		'twdefault' 	=> ' '
	) );
		$wp_customize->add_control( 'parallaxone_twitter_select', array(
		'label'     => __( 'Twitter', 'parallaxone' ),
		'section'   => 'parallaxone_social_options_section',
		'priority'  => 20,
		'type'      => 'text'
	) );

Open in new window


And here is my front end code on the home page;

<?php $fbdef = get_theme_mod( 'parallaxone_facebook_select', $fbdefault);
					if ($fbdef !== $fbdefault) { ?>
					<img src="<?php bloginfo('template_directory'); ?>/images/social/facebook-social.png" />
                    <?php } ?>	
                    
					<?php $twdef = get_theme_mod( 'parallaxone_twitter_select', $twdefault);
					if ($twdef !== $twdefault) { ?>
					<a href="http://www.twitter.com/<?php echo $twdef; ?>"><img src="<?php bloginfo('template_directory'); ?>/images/social/twitter-social.png" /></a>
                    <?php echo $twdefault; ?>
                    <?php } ?>

Open in new window


Basically, what I want to happen is for the social media image to only show if there is a value given by the user.  It works fine for the FB setting and control, but doesn't seem to work for the Twitter Setting and Control.  It shows if either is active. and a blank text box doesn't seem to reset the default to ' ',

I think that is the issue here, but not sure how to reset the text value when no data is provided.
ASKER CERTIFIED SOLUTION
Avatar of axessJosh
axessJosh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial