1

I've set up a new section in the customizer called Social Links, under which I've set up an option and text field control called Facebook. Here's the code in my functions.php:

// SOCIAL LINKS
$wp_customize->add_section( 'social_links_section' , array(
    'title'      => __( 'Social Links', 'my_theme' ),
    'priority'   => 100,
) );
// Facebook
$wp_customize->add_setting( 'social_link_facebook' , array(
    'default' => ''
) );
$wp_customize->add_control(
    'social_link_facebook', 
    array(
        'label'    => __( 'Facebook', 'my_theme' ),
        'section'  => 'social_links_section',
        'settings' => 'social_link_facebook',
        'type'     => 'url',
    )
);

But when I try to get the value of social_link_facebook in my theme template files, it isn't returning anything. Here's the code from my header.php:

<?php $facebook = get_option( 'social_link_facebook' );
if( !empty($facebook) ) { ?>
    <a href="<?php echo $facebook ?>" target="_blank" ><span class="dashicons dashicons-facebook-alt"></span></a>
<?php } ?>

Any idea why this might be?

2
  • You should use get_theme_mod. Commented May 23, 2016 at 14:49
  • @LuisSanz Thanks! I wasn't expecting it to be that simple, now I feel stupid :P Commented May 23, 2016 at 15:08

1 Answer 1

1

There are two ways to solve this:

1 Keep the mods as they are and use get_theme_mod in stead of get_option

2 Store the mods as options by changing the setting:

$wp_customize->add_setting( 'social_link_facebook' , array(
    'default' => '',
    'type' => 'option'
) );
1
  • Thanks, I used get_theme_mod and that did the trick :) Commented May 23, 2016 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.