Create a Custom Function to Automatically Add a Disclaimer to All Posts

Sarah K Dec 19, 2024 Custom Functionality
How can I make sure every blog post I write includes a standard disclaimer at the bottom?
What is the best way to programmatically add a disclaimer to the footer of all WordPress posts using a custom function in my theme's functions.php file?
Andy answered Dec 19, 2024

Solution to Add Automatic Disclaimer to Posts

Custom Code Solution

Here's a function that adds a disclaimer to the end of all post content. Add this code to your theme's functions.php file or in a site-specific plugin:

This function hooks into WordPress content filter and appends the disclaimer:

function add_post_disclaimer($content) {
    // Only add to single posts, not pages or other post types
    if (is_single() && get_post_type() === 'post') {
        // Your disclaimer text - modify this as needed
        $disclaimer = '<div class="post-disclaimer">
            <h4>Disclaimer</h4>
            <p>This article is for informational purposes only. The content represents the views of the author.</p>
        </div>';
        
        // Append disclaimer to content
        $content .= $disclaimer;
    }
    return $content;
}
add_filter('the_content', 'add_post_disclaimer');

To style the disclaimer, add this CSS to your theme's stylesheet:

function add_disclaimer_styles() {
    $custom_css = "
        .post-disclaimer {
            margin-top: 30px;
            padding: 20px;
            background-color: #f8f8f8;
            border-left: 4px solid #666;
        }
        .post-disclaimer h4 {
            margin-top: 0;
            color: #333;
        }";
    wp_add_inline_style('your-theme-style', $custom_css);
}
add_action('wp_enqueue_scripts', 'add_disclaimer_styles');

Variations

To add the disclaimer only to specific categories:

function add_category_specific_disclaimer($content) {
    // Add disclaimer only to posts in category with ID 5
    if (is_single() && has_category(5)) {
        $disclaimer = '<div class="post-disclaimer">
            <h4>Category Specific Disclaimer</h4>
            <p>This is a special disclaimer for this category.</p>
        </div>';
        $content .= $disclaimer;
    }
    return $content;
}
add_filter('the_content', 'add_category_specific_disclaimer');

Plugin Solutions

If you prefer a plugin solution, here are reliable options:

  1. Simple Custom CSS and JS - Allows adding custom HTML/CSS/JS including disclaimers
  2. Footer Putter - Specifically designed for adding content to post footers
  3. Insert Headers and Footers - Can add custom content to various parts of your posts

Additional Notes

  • The custom code solution is lightweight and doesn't require additional plugins
  • Disclaimer text can be easily modified in the code
  • The styling can be customized by modifying the CSS
  • You can adapt the conditions to show the disclaimer on different post types or specific categories
  • Make sure to backup your functions.php file before adding new code