I am currently working on a theme/website in WordPress for a business and I would like to add additional details such as the contact number, email address, etc. which can then be referenced on any page of the site.
This information is used on multiple sections and pages on the site and I would like to avoid redundancy which would cause issues when having to update those details.
Is anyone aware of any way I can get this done in WordPress?
Depends on what you want do do and how you want the content to be displayed.
You can create a new menu section in Customizer using the Customization API, where you or the client can simply add or update their contact info. Add to functions.php:
<?php
function contact_info( $wp_customize ) {
$wp_customize->add_setting( 'contact_info_email', array(
'default' => 'name@company.com',
));
$wp_customize->add_setting( 'contact_info_phone', array(
'default' => '+420123456789',
));
$wp_customize->add_section( 'contact_info_section', array(
'title' => __( 'Company Information', 'rsp' ),
'priority' => 20,
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'contact_info_email_control', array(
'label' => __( 'Email address', 'textdomain' ),
'section' => 'contact_info_section',
'settings' => 'contact_info_email',
)));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'contact_info_phone_control', array(
'label' => __( 'Phone number', 'textdomain' ),
'section' => 'contact_info_section',
'settings' => 'contact_info_phone',
)));
}
add_action( 'customize_register', 'contact_info' );
?>
To display the content on the frontend you would use:
<?php echo get_theme_mod( 'contact_info_email', 'name@company.com' ); ?>
<?php echo get_theme_mod( 'contact_info_phone', '+420123456789' ); ?>
Then it's just a matter of putting it in HTML and styling it appropriately. You can put it inside a navbar or footer or anywhere else.