
For some reason, you may want to be able to automatically display a custom text below each of your posts. You can hard-code it, but it will be way better to do so using a WordPress hook. Here’s how to do.

For some reason, you may want to be able to automatically display a custom text below each of your posts. You can hard-code it, but it will be way better to do so using a WordPress hook. Here’s how to do.
You just have to paste the following code into your functions.php and save the file. Once done, custom content will be inserted below each of your posts.
function add_post_content($content) {
if(!is_feed() && !is_home()) {
$content .= '<p>This article is copyright © '.date('Y').' '.bloginfo('name').'</p>';
}
return $content;
}
add_filter('the_content', 'add_post_content');
Thanks to Jeff Starr for the great snippet!
By the way, if you need any kind of WordPress help I'm happy to inform you that I'm starting to work freelance. Don't hesitate to contact me to get a quote for your new project!
16 Responses
usefull
) tanks !
Thats a great tip
Maybe I’m missing something, can’t you just code this in your theme’s single or post template? What ever you type after the post will appear on every single or page template?
great tip. Thank you
Does this also update the RSS feed with the additional content?
Consider this recipe used.
Thanks!
I love your site. I would find it the example much clearer if you showed an example of this in action. Many thanks!
This is useful for applying reoccurring content on all your posts like : copy write information, contact info or a signature.
Cool! Thanks
I’m with Neal unless I’m missing the point.
Cool. This would suit a significant amount of users, but what about the ones that want more flexibility? The idea I’m suggesting involves the use of custom fields on ‘single’ post articles.
Consider something like this one:
function add_post_content($content) {
if(is_single()) {
$custom_content = get_post_meta($post->ID, ‘Custom Content’);
if(is_empty($custom_content)) {
$content .= ‘This article is copyright © ‘.date(‘Y’).’ ’.bloginfo(‘name’).”;
}else{
$content .= $custom_content;
}
}
return $content;
}
add_filter(‘the_content’, ‘add_post_content’);
You will have to set a custom field key of ‘Custom Content’[without the single quotes].
I aint tested this yet but you can hopefully see where I’m going with this. There are many possibilities with this one, including changing the code so that you can add a custom message plus the copyright message. To do this simply add:
$content .= ‘This article is copyright © ‘.date(‘Y’).’ ’.bloginfo(‘name’).”;
Just below the:
$content .= $custom_content;
So the copyright will be there either way and you can tweak the code and add an activating/deactivation option for the copyright message for certain posts you may not want it to appear in, as you create another custom field giving this option.
You can check the link below on understanding custom fields for those not familiar:
codex.wordpress.org/Function_Reference/get_post_meta
All the best
Amazing little trick that saves a lot!
Already adopted on my blog, thank you =)
Nice snippets! Tested and works.
This is awesome! Thanks for the code. I’ve been looking for smth extraordinary to make on my blog and that’s it!
Really very useful tips.Thanks for sharing.
Hey.. It was really great tip.. I’m going to try this.. Many thanx !
Thanks for the great tip. I am using this together with the Supple Forms plugin, the author have not yet enable this feature and this is just what I need.
Thanks again.
@Neal and 401k
Yes you could code it into a theme if you were just adding copyright data or some random text and had a custom theme.
However I am creating a plugin which will be adding data to the end of the post. This post hit the spot for my problem.
Thanks
Trackbacks: