Adding a Custom Footer Message
Method 1: Using Functions.php (Recommended)
Add this code to your theme's functions.php
file or in a site-specific plugin. It will add a custom message to the footer using the WordPress native wp_footer
hook:
function add_custom_footer_message() {
echo '<div class="footer-message">';
echo 'Your custom footer message here. © ' . date('Y') . ' All Rights Reserved.';
echo '</div>';
}
add_action('wp_footer', 'add_custom_footer_message');
To style your footer message, add this CSS to your theme's stylesheet or Customizer:
function add_footer_message_styles() {
echo '<style>
.footer-message {
text-align: center;
padding: 20px;
background: #f5f5f5;
margin-top: 20px;
}
</style>';
}
add_action('wp_head', 'add_footer_message_styles');
Method 2: Dynamic Footer Message with Settings
This more advanced solution adds a customizable footer message through the WordPress Customizer:
function footer_message_customizer($wp_customize) {
$wp_customize->add_section('footer_message_section', array(
'title' => 'Footer Message',
'priority' => 120
));
$wp_customize->add_setting('footer_message_text', array(
'default' => 'Your custom footer message here',
'sanitize_callback' => 'wp_kses_post'
));
$wp_customize->add_control('footer_message_text', array(
'label' => 'Footer Message',
'section' => 'footer_message_section',
'type' => 'textarea'
));
}
add_action('customize_register', 'footer_message_customizer');
function display_custom_footer_message() {
$message = get_theme_mod('footer_message_text');
if ($message) {
echo '<div class="footer-message">' . wp_kses_post($message) . '</div>';
}
}
add_action('wp_footer', 'display_custom_footer_message');
Plugin Alternative
If you prefer using a plugin, here are reliable options:
-
Footer Text - Simple plugin for adding custom footer text
-
Insert Headers and Footers - Adds custom code to header/footer
Important Notes:
- Place code snippets in your child theme's
functions.php
file
- Test the code in a development environment first
- Adjust CSS styles to match your theme's design
- Use
wp_kses_post()
for security when outputting HTML content
- Remember to escape dynamic content properly
- Consider mobile responsiveness when styling the footer message
The Customizer method (Method 2) is ideal for clients who need to update the footer message without editing code.