Take the 2-minute tour ×

As the title says I want to keep images on pages and hide them from posts on my site . How can I do this? Thanks

share|improve this question

2 Answers 2

up vote 0 down vote accepted

You can do this with a css solution. Pages and posts have different body_classes, so you should be able target them with page and post respectively. Your CSS would look something like this:

.post img {
    display: none
share|improve this answer
Perfect, thanks –  Nick Mar 2 '12 at 17:44
please mark the question as solved if this was working solution. –  m0r7if3r Mar 2 '12 at 17:45
This (to me) is both correct and wrong. It's absolutely correct if you truly to wish to just hide the image. However, this will still produce an HTTP request that has no purpose and technically increases your page load time. If you happen to have a post with a handful of large, hi-res images your page load time could potentially take a beating for images that aren't going to show anyways. –  cmegown Mar 2 '12 at 19:47

I suppose that you could check whether your "Post Type" is a Page or a Post using this function ( link to the Codex at Post Types )

Also this function will come in handy to get the current post type: get_post_type, doc here

Edit: The CSS Solution of m0r7if3r is also elegant. But is the image actually loading ( by the browser ) with display:none ? Meaning that if it is loaded, the website will become heavier for something not visible. But I'm not sure about the behavior of image loading with css display:none. Any thought on that?

share|improve this answer

Your Answer


