Show code on Single Post page only – WordPress

While working on wordpress, there might be something you wanna show on your single post page only and not on every content page of your wordpress blog or website.

wordpressThis can be done by using builtin is_single() function of wordpress. Showing ads (adsense ofcourse ?) on your single post page only and not on other pages like contact or about us.

Well I’ve been trying to put the code in functions.php of my wordpress theme to add the adsense code before and after my blog post but not to show it on regular pages of the website.

To do this, the code theme has to go like this in functions.php file of your wordpress theme:

add_action(‘the_content’, sharebox);

function sharebox($content){

if(is_single()) {

$nabtron_before_content = “stuff to show before content”;

$nabtron_after_content = “stuff to show after content”;

$content = $nabtron_author_adsense.$content.$nabtron_after_content;



Please note, that “is_single()” check has to be inside the function to work, it won’t work outside of it on the add_action line.

This will simply add your stuff to show before content , before the main content body, and the stuff to show after content will be displayed after the content. You can add ads code here or any other code.

Please note that the WordPress built in function “is_post()” is now deprecated and will trigger an error saying that call to an undefined function or similar one.

Let me know if you have any other ideas or if you have trouble with this thing :)

Leave a Reply

Your email address will not be published.