Add Text To Bottom Of Every Post in WordPress
Maintaining and upgrading a website sometimes becomes a headache when you have to remember all the custom changes done till date. So to avoid this situation I usually create a ‘how to article’ on the same so that in case of any theme changes, all my custom changes can be traced back & reapplied. Similarly in this article we will explain a quick method to add text to bottom of every post in WordPress. For example here we added a copyright text below to every post.
In my scenario I had to add a copyright disclaimer text to the end of each post for easy reference by someone. If you are looking to add some other text with html content also it works just fine. To achieve the same we have to follow below steps:
1. Login to your WordPress site wp-admin console.
2. Navigate to Appearance>Editor
3. Search for Theme Functions (functions.php) file and click on it to start the edit.
Note: It is wise to take a backup of existing working functions.php before editing to revert back in case of any issues.
4. Add below given code to the end of the Theme Functions (functions.php) file.
Code to add text after every post content:
add_filter('the_content','add_my_content'); function add_my_content($content) { $my_custom_text = '<p><font size="2">In case of any ©Copyright issues please check <a href="http://www.techpaste.com/disclaimer/">CopyRights</a> page for faster resolutions.</font></p>'; // if(is_single() && !is_home()) { $content .= $my_custom_text; } return $content; }
Bonus Code to add text before every post content:
add_filter('the_content','add_my_content'); function add_my_content($content) { $my_custom_text = 'Place the text you wish to insert before your post content here inside the single quotes only.'; if(is_single() && !is_home()) { $content = $my_custom_text.$content; } return $content; }
Sample Screenshot:
5. Click on Update file to get the code change take effect.
6. If you have caching plugins installed then delete the cache to see the changes take effect.
Check out end of this posts content you will be able to see the inserted text via code. If you like the post then please like and share the same.
In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.
What if I want that text to be bold? Thank you.
just try using it like < b >TEXT < / b >
https://www.w3schools.com/html/html_formatting.asp
Thank you. Very useful for me
How can this be made to work on pages instead of, or in addition to posts?
Add is_page() to the conditional sentence like
if(is_single() && !is_home() && !is_page()) {
Thank you so much!! This was extremely useful to me. There were other sites that recommended doing the same thing as you, but instead of using code after my_custom_text (your example: $my_custom_text = ‘
In case of any ©Copyright issues please check CopyRights page for faster resolutions.
‘; //), they just wrote out your other example, which to me doesn’t work (your example: $my_custom_text = ‘Place the text you wish to insert before your post content here inside the single quotes only.’;).
Using my_custom_text without using html code afterwards (in this case
) doesn’t work for me at all (it throws out a syntax error on that particular line, but when I put it in
brackets it works perfectly), so thank you for using the example with html code as well (I didn’t even know I could insert the html code in this php script – obviously I have little to no experience with php).
So for anyone that gets a syntax error without using html after my_custom_text, just use html code there and it should work great.
Thanks again, 🙂
J.
In my above comment the html code got deleted/integrated so it makes less sense, but in short, html code was needed to me (in this case the p, paragraph html) after the my_custom_text string in order to make the text appear at all
Thank you
Thanks.. Worked like charm.. 🙂
It worked. Thank you 🙂
working but my slider went to bottom after adding this 🙁 please help me
This is great! How do you exclude additional post types. Some 3rd party plugins and/or themes create custom post types, such as FAQs, Portfolios, or in one of my cases, a Team Bio / Directory listing plugin which is now displaying the custom text which not only do I not need, looks a little goofy.
Thanks. A simple and elegant solution. If we ever meet, I owe you a beer.
Thanks for the clean code. But the text appears after the post title and image. Is there a way to display this text before the post’s title? Thanks much appreciated
This is great! How would I make the words a link for users to click on. I’ve tried this but i get an error that link is expired. Any idea on how to fix this?