Wordpress Hack: Anything Can Be Added Anywhere In The Post Content
Spread it!
Some of wordpress plugins automatically add their display below your post content which is such as: YARPP (Related Posts) or Sociable …. They added their displays into your post content, but sometime, you want to add your own code before them, even between the introduction and the main content. This article will tell you how to add anything to your wordpress theme just right before others plugin do.
This is the first tutorial that I don’t offer the download link. Just follow these simple steps and you’ll get the nice results.
Hack your theme functions.php file
The only thing you want to do is just hack your theme functions.php file.
Open this file.
In this article, I will add the author bio box into wordpress theme before the Related Posts displays. Write a function that return the author bio box, you can write anywhere, but at the end of your functions.php is avoid messing up your file:
function get_author_bio ($content=''){ if(!in_category("Community News")) { $post_author_name=get_the_author_meta("display_name"); $post_author_description=get_the_author_meta("description"); $html="<div class='clearfix' id='about_author'>\n"; $html.="<img width='80' height='80' class='avatar' src='http://www.gravatar.com/avatar.php?gravatar_id=".md5(get_the_author_email()). "&default=".urlencode($GLOBALS['defaultgravatar'])."&size=80&r=PG' alt='PG'/>\n"; $html.="<div class='author_text'>\n"; $html.="<h4>Author: <span>".$post_author_name."</span></h4>\n"; $html.= $post_author_description."\n"; $html.="</div>\n"; $html.="<div class='clear'></div>\n"; $html.="</div>"; $content .= $html; } return $content; }
In Wordpress 2.8 and above, the_author_description(); has been deprecated and replaced with another function: the_author_meta(‘description’);. However, you have to use get_the_author_meta() if you need to return (not display) the information. Take a look at this function’s information at Wordpress Codex.
In this function, I set the condition that the bio box will not display if this post is in Community News category. I’m using the same as above. This function is not return the bio box, it joins the post content and bio box content into one.
Next, you need to hook this function to the_content with code:
add_filter('the_content', 'get_author_bio');
For the example, before you use this hack, your bio box will display after the Related Posts, likes this:

But after you did some hacks in functions.php file, you will get a result likes mine at the end of this post.
To display something at the begin, easy as adding it normally into your post theme file: single.php
Sometime, you want to display your ads right below your post’s introduction. We will need to split the content into two parts, then insert ads code at the middle. Let’s write a function likes this:
function put_middle_content($content='') { if ( preg_match('/<span id="(.*?)?"><\/span>/', $content, $matches) ) { $content = explode($matches[0], $content, 2); $content = $content[0] . $matches[0] . '[YOUR ADS ARE HERE]' . $content[1]; } return $content; }
If your post has More tag, this function will split the content into 2 parts with delimiter is the More tag. Then, It will combine the content array again with the adding between 2 array strings.
Adding the code below to complete:
add_filter('the_content', 'put_middle_content');
That’s all
Yup, that’s all. Now, you can add anything you want to anywhere, such as: top, middle, and right after the post content that you could not do with the template display file. Your adding’s priority will be always the first.
66 User Comments
Trackbacks/Pingbacks
-
-
24. Oct, 2009
[...] the rest here: Wordpress Hack: Anything Can Be Added Anywhere In The Post Content Related [...]
-
-
24. Oct, 2009
[...] This post was mentioned on Twitter by Shurandy Thode and Lam Nguyen, Web Design News. Web Design News said: Wordpress Hack: Anything Can Be Added Anywhere In The Post Content http://bit.ly/4lUFbA [...]
-
-
25. Oct, 2009
[...] Wordpress Hack: Anything Can Be Added Anywhere In The Post Content [...]
-
-
25. Oct, 2009
[...] Wordpress Hack: Anything Can Be Added Anywhere In The Post Content [...]
-
-
25. Oct, 2009
[...] is the original post: Wordpress Hack: Anything Can Be Added Anywhere In The Post Content | AEXT.NET Comments0 Leave a Reply Click here to cancel [...]
-
-
26. Oct, 2009
[...] Wordpress Hack: Anything Can Be Added Anywhere In The Post Content | AEXT.NET [...]
-
-
26. Oct, 2009
[...] to Lam Nguyen for this cool little trick! If you enjoyed this article, please consider sharing it! [...]
-
-
26. Oct, 2009
Wordpress Hack: Anything Can Be Added Anywhere In The Post Content…
Learn how to add anything to anywhere in the wordpress post content with a small wordpress hack….
-
-
27. Oct, 2009
[...] Wordpress Hack: Anything Can Be Added Anywhere In The Post Content [...]
-
-
27. Oct, 2009
[...] Wordpress Hack: Anything Can Be Added Anywhere In The Post Content [...]
-
-
28. Oct, 2009
[...] Wordpress Hack: Anything Can Be Added Anywhere In The Post Content [...]
-
-
30. Oct, 2009
[...] Wordpress Hack: Anything Can Be Added Anywhere In The Post Content [...]
-
-
02. Nov, 2009
[...] » Source: http://aext.net/2009/10/wordpress-hack-anything-can-be-added-anywhere-in-the-post-content/ [...]
-
-
02. Nov, 2009
[...] » Source: http://aext.net/2009/10/wordpress-hack-anything-can-be-added-anywhere-in-the-post-content/ [...]
-
-
04. Nov, 2009
[...] $content; } add_filter('the_content', 'get_author_bio');</div> Source: http://aext.net/2009/10/wordpress-hack-anything-can-be-added-anywhere-in-the-post-content/Compress WordPress output and speed your blog’s load speedIs your host slow? Althought on [...]
-
-
04. Nov, 2009
[...] » Source: http://aext.net/2009/10/wordpress-hack-anything-can-be-added-anywhere-in-the-post-content/ [...]
-
-
04. Nov, 2009
[...] building an author bio box for each post [...]
-
-
05. Nov, 2009
[...] building an author bio box for each post [...]
-
-
06. Nov, 2009
[...] building an author bio box for each post [...]
-
-
06. Nov, 2009
[...] building an author bio box for each post [...]
-
-
07. Nov, 2009
[...] Wordpress Hack: Anything Can Be Added Anywhere In The Post Content Wordpress: Ajouté la fiche de l'auteur dans un article et insérez de la pub après l'intro [...]
-
-
13. Nov, 2009
[...] $content .= $html; } return $content; } add_filter('the_content', 'get_author_bio'); Source: http://aext.net/2009/10/wordpress-hack-anything-can-be-added-anywhere-in-the-post-content/ Share and [...]
-
-
15. Nov, 2009
[...] Source… [...]
-
-
17. Nov, 2009
[...] In: Wordpress plugins 17 Nov 2009 Go to Source [...]
-
-
20. Nov, 2009
[...] want to credit Lam Nguyen for this helpful little hack that I found in his post on this [...]
-
-
23. Nov, 2009
[...] » Source: http://aext.net/2009/10/wordpress-hack-anything-can-be-added-anywhere-in-the-post-content/ [...]
-
-
01. Dec, 2009
[...] Source: AEXT.NET [...]
-
-
08. Dec, 2009
[...] Source Link [...]
-
-
08. Dec, 2009
[...] Source Link [...]
-
-
10. Dec, 2009
[...] Source Link [...]
-
-
11. Dec, 2009
[...] your post content which is such as: YARPP (Related Posts) or Sociable …. Continued here: Click Here…Read Other Interesting Posts in PHP TutorialsThe ways to create thumbnail image by php with [...]
-
-
16. Dec, 2009
[...] Source: AEXT.NET [...]
-
-
23. Dec, 2009
[...] » Source: http://aext.net/2009/10/wordpress-hack-anything-can-be-added-anywhere-in-the-post-content/ [...]
-
-
29. Dec, 2009
[...] Source [...]
-
-
15. Jan, 2010
[...] Source [...]
-
-
21. Jan, 2010
[...] coupe of months ago, I published a post Wordpress Hack: Anything Can Be Added Anywhere In The Post Content. With that tutorial, you can add anything in WordPress posts on top, bottom before other plugins [...]
-
-
25. Jan, 2010
[...] 26.How To Insert Author Bio On Each Post [...]
-
-
26. Jan, 2010
[...] 26.How To Insert Author Bio On Each Post [...]
-
-
26. Jan, 2010
[...] for Lam Nguyen Share and [...]
-
-
26. Jan, 2010
[...] 26.How To Insert Author Bio On Each Post [...]
-
-
16. Feb, 2010
[...] Hack: Add Anything, Anywhere To Post good for adding adsense codes… http://aext.net/2009/10/wordpress-ha…-post-content/ __________________ _/_/_/_/ _/TSP_/ [...]
-
-
23. Feb, 2010
[...] 26.How To Insert Author Bio On Each Post [...]
-
-
23. Feb, 2010
[...] Source [...]











thanks for thes info.
Thanks for the hack!
How did you know I was looking for this exact hack today? Wow – very cool timing!
Because some of my clients want to add some ads code inside post content.
Thanks for enjoy reading!
Very clever and useful!
Nice hack Dude !! Just got your link from WP Recipes. This is really a beautiful to look at site… lots of eye candy and great title selection. I’m impressed. Now all you need is some PR on your homepage.
This is awesome Lam! Very cool.. Thank you Sir
@Mal Milligan: Thank you
, but I’m not good at page rank increasing. You’re correct, and I’ll try to increase my page rank.
Hi Lam,
I would like to know if we can get the total no. of posts by a specific user?
Take a look at this, may it helps you!
http://wordpress.org/support/topic/217402
I recently came across your blog and have been reading along. I thought I would leave my first comment. Nice post!
I was finding from so many days finally found it. Thanks very much.Please tell me how to give style to it.It is coming plain text so i want to add some background.
And aslo a thing like visit website and follow on twitter.
Never mind thanks got it.
Lam, your site simply ROCKS ! most informative & clearly defined, easy to understand for even a beginner like me
Thank you so much for sharing all your knowledge . Wishing you much continued future success within your career endeavors .
Best wishes , M.
Really nice code, thanks for sharing ;D
How do I customize the box via CSS that is what I am looking at. It worked like a charm…but no way I can customize this ?
It’s easy that you can do by add css style by the id and class name of the elements.
Thanks for the hack. Its very obvious even for fellow bloggers.
This is amazing. I learnt it works wven with WPMU. Does it work with buddypressed WPMU?
I’ve never used WPMU before, so I’m not sure
Its work in 2.9.
Its seem not working in me
hi Lam, thanks for the information about wp. can you pls do more post related to wp hacks. it will very helpful for the beginner like me.
This will also appears in pages. what is the workaround to make it appear only in post?
insic´s last blog ..WPBuzzer Wordpress Plugin Workaround