views:

68

answers:

2

i want to display custom html code when a post is rendered (so not when is inserted into db).

I currently do this with *add_filter('the_content', 'my_custom_method')*. The only problem is that i want this do be displayed only inside the post (when is viewed in its own page), not when all posts are rendered .

I banged my head against the wall, but couldn't find any method to tell me if i'm currently inside an individual post or not (this has to work for every url rewriting possible, so i can't rely on url)

Is there such a method? I believe it should be, but i can't find it. Thanks.

A: 

The easiest way to do this would be to modify your templates. Wordpress template sets should have a file named single.php (inside wp-content/themes/<theme name>). This is the page that gets rendered when you are viewing the page for a single post.

You could edit this file and insert whatever you needed to for the posts there.

zombat
thank you! unfortunetly i can mark only one answer as accepted answer, though both answers are great. Thanks!
paul
A: 

the function for checking if the post is in its own page is is_single()

add_filter('the_content', 'my_custom_method');

function my_custom_method(){
    if(is_single()){
        //code for your custom html code
    }
}

the function is_single() checks if the page being rendered is a single page or not.

Pragati Sureka
thank you so much
paul