Content of custom WordPress template not showing on page
all
I am working with a custom WordPress theme that I developed for a website. I have a box on the left side of the footer for a postal address and I want this to be editable using the theme customizer in WordPress. I added the appropriate field to the customizer, but the content of the field is not displayed on the page.
In the functions.php function, the following code adds a field to the theme setting:
//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 corresponding markup is:
<p class="col md-4 text-muted" id="footer_address"><?php echo get_theme_mod('footer_address_text'); ?></p>
The field content is not displayed on the page.
source to share
add_setting()
registers the wrong id and add_control()
does not need to new WP_Customize_Control($wp_customize, )
add the default field only if a custom class is created WP_Customize_*
.
$wp_customize->add_setting(
'footer_address_text',
array(
'default' => '100 Main Street | Anytown, USA',
'sanitize_callback' => 'sanitize_footer_address'
)
);
$wp_customize->add_control(
'footer_address',
array(
'label' => 'Address to appear on left side of footer',
'section' => 'Footer',
'settings' => 'footer_address_text',
'type' => 'text'
)
);
source to share