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.
Like the article? Be sure to subscribe to our RSS feed and follow us on Twitter to stay up on recent content.
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.phpfile.
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.


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 =-.
I’m having a problem with my one. The code works but then it moved the right sidebar column underneath my post. What should I do? I really need a author bio >_<''
.-= Stevo´s last blog ..Hello world! =-.
I have the same problem as you
.-= hydir´s last blog ..Kesedihan adalah ubat, gembira adalah penawar =-.
you guys should check for XHTML validation!
one more thing .. why this code shown on frontpage also.
I expect is is only visible on post page only. Any idea?
btw .. how to do some CSS for this bio box? I’m a newbie for wordpress environment
.-= hydir´s last blog ..Kesedihan adalah ubat, gembira adalah penawar =-.
Hello Lam,
I have tried to put this code to my blog but it give weird outcome. As I used the code from http://www.instantshift.com/2009/12/08/22-latest-exceptional-wordpress-hacks/ and it refer to you as the source, I wonder if you could help me to sort out this problem.
I put the code in functions.php yet the avatar didn’t show up and also is shows in the front page. Any idea?
.-= hydir´s last blog ..Kesedihan adalah ubat, gembira adalah penawar =-.
Hi Lam, thanx for the great hacks!;D
but, can you help me please????
how to make related post side by side with other ads such as sociable etc..
please…i really appreciate it..
thank you…
Like it !!
That’s a real cool bit of code