all
I’m working with a custom WordPress theme that I developed for a site. I have a field on the left side of the footer for a mailing address, and I want this to be editable via the theme customizer in WordPress. I’ve added the field in question to the customizer, but the content of the field is not displaying on the page.
In functions.php, the following code adds the field to the theme customizer:
//Adds footer address to theme customizer
function sanitize_footer_address($input){
return strip_tags(stripslashes($input));
}
function portfolio_customize_register($wp_customize){
$wp_customize->add_section(
'Footer',
array(
'title' => __('Left Footer Content', 'portfolio'),
'priority' => 200
)
);
$wp_customize->add_setting(
'footer_address',
array(
'default' => '100 Main Street | Anytown, USA',
'sanitize_callback' => 'sanitize_footer_address'
)
);
$wp_customize->add_control( new WP_Customize_Control(
$wp_customize,
'footer_address',
array(
'label' => 'Address to appear on left side of footer',
'section' => 'Footer',
'settings' => 'footer_address_text',
'type' => 'text'
)
)
);
}
add_action(customize_register, portfolio_customize_register);
In the footer.php template, the relevant markup is:
<p class="col md-4 text-muted" id="footer_address"><?php echo get_theme_mod('footer_address_text'); ?></p>
The content of the field does not display on the page.
add_setting()
is registering the wrong ID andadd_control()
doesn’t neednew WP_Customize_Control($wp_customize, )
when adding a default field, only when a customWP_Customize_*
class is created.