Custom Footer Message Solution
Method 1: Custom Code Solution
First, let's create a custom option in WordPress admin to store and update the footer message.
Add this code to your theme's functions.php
:
This code creates the admin menu item and settings field:
function custom_footer_admin_menu() {
add_menu_page(
'Footer Settings',
'Footer Message',
'manage_options',
'custom-footer-settings',
'custom_footer_settings_page',
'dashicons-admin-generic',
99
);
}
add_action('admin_menu', 'custom_footer_admin_menu');
function custom_footer_settings_page() {
if (isset($_POST['footer_message'])) {
update_option('custom_footer_message', wp_kses_post($_POST['footer_message']));
echo '<div class="updated"><p>Footer message updated!</p></div>';
}
$message = get_option('custom_footer_message', '');
?>
<div class="wrap">
<h2>Custom Footer Message</h2>
<form method="post">
<textarea name="footer_message" rows="5" style="width: 100%;"><?php echo esc_textarea($message); ?></textarea>
<p><input type="submit" class="button button-primary" value="Save Message"></p>
</form>
</div>
<?php
}
This code adds the footer message to your site:
function display_custom_footer_message() {
$message = get_option('custom_footer_message');
if (!empty($message)) {
echo '<div class="custom-footer-message">' . wp_kses_post($message) . '</div>';
}
}
add_action('wp_footer', 'display_custom_footer_message');
Add this CSS to your theme's style.css
:
.custom-footer-message {
text-align: center;
padding: 20px;
background: #f9f9f9;
border-top: 1px solid #ddd;
}
Method 2: Plugin Solutions
If you prefer using a plugin, here are reliable options:
-
Footer Text - Simple plugin for custom footer text
-
Insert Headers and Footers - More features, including custom HTML/scripts
Usage Instructions:
- Add the PHP code to your theme's
functions.php
- Add the CSS to your theme's
style.css
- Go to WordPress admin panel
- Look for "Footer Message" in the left menu
- Enter your desired footer message
- Click "Save Message"
The message will appear at the bottom of every page on your site. You can update it anytime through the admin panel.
Note: This solution includes basic security measures (wp_kses_post) and follows WordPress coding standards. Adjust the CSS styling to match your theme's design.