Custom PHP Snippet to Display a Footer Message in WordPress

Luca M Jan 4, 2025 WordPress Customization
How can I add a special message at the bottom of my website?
What is the custom PHP snippet to hook into the WordPress footer to display a custom message?
Andy answered Jan 4, 2025

Adding a Custom Footer Message in WordPress

Custom Code Solution

The following code hooks into the wp_footer action to display a custom message at the bottom of your website. Add this code to your theme's functions.php file or in a site-specific plugin:

Basic footer message implementation:

function add_custom_footer_message() {
    echo '<div class="custom-footer-message">';
    echo 'Your custom message here. © ' . date('Y') . ' All rights reserved.';
    echo '</div>';
}
add_action('wp_footer', 'add_custom_footer_message');

Styled footer message with more customization options:

function add_styled_footer_message() {
    $message = 'Your custom message here'; // Change this text
    $year = date('Y');
    
    echo '<div class="custom-footer-message" style="
        text-align: center;
        padding: 20px;
        background-color: #f5f5f5;
        margin-top: 20px;
    ">';
    echo sprintf('%s © %s All rights reserved.', $message, $year);
    echo '</div>';
}
add_action('wp_footer', 'add_styled_footer_message');

Alternative implementation with customizable message from WordPress admin:

// Add option to WordPress admin
function register_footer_message_setting() {
    register_setting('general', 'custom_footer_message');
    add_settings_field(
        'custom_footer_message',
        'Footer Message',
        'footer_message_callback',
        'general'
    );
}
add_action('admin_init', 'register_footer_message_setting');

function footer_message_callback() {
    $message = get_option('custom_footer_message');
    echo '<input type="text" name="custom_footer_message" value="' . esc_attr($message) . '" class="regular-text">';
}

// Display the message
function display_custom_footer_message() {
    $message = get_option('custom_footer_message');
    if (!empty($message)) {
        echo '<div class="custom-footer-message">';
        echo esc_html($message) . ' © ' . date('Y');
        echo '</div>';
    }
}
add_action('wp_footer', 'display_custom_footer_message');

Plugin Solutions

If you prefer using a plugin, here are some reliable options:

  1. Footer Text Plugin - Simple plugin to add and edit footer text
  2. Simple Custom CSS and JS - Allows adding custom HTML/CSS/JS including footer content

Placement Instructions

  1. For custom code: Add to your theme's functions.php file or create a site-specific plugin
  2. If using a child theme (recommended), add to the child theme's functions.php
  3. To create a site-specific plugin, create a new PHP file in the /wp-content/plugins directory

Additional Notes

  • The code uses the WordPress native wp_footer hook, which works with most themes
  • The styled version includes basic CSS; adjust the styles to match your theme
  • The admin option version allows editing the message from Settings → General
  • Remember to escape output when displaying user-input content
  • Test the implementation in a staging environment first