Show image exactly defined to a width

I have a photoblog displaying posts as image galleries having width 500px and some posts as single image of width 900px. For posts with 900px width images, I made category HQ.

Posts with 500px width image galleries display fine. But those posts having single image doesn’t display image of width 900px width instead 584px. E.g. Post content for 900px width image:

Read More
<img class="alignnone size-full wp-image-15735" alt="Camping in the Rocky Mountains " src="http://abc.com/wp-content/uploads/2013/05/Camping-in-the-Rocky-Mountains.jpg" width="900" height="700" />

Getting image info in browser shows 584px width. On further inspection, I came to know that there is a $content_width variable in functions.php set to 584px. I can’t change it as I read it is for oEmbeds.

How to get this 900px width image to show as 900px width?

Related posts

2 comments

  1. If $content_width is the problem, you could set it to something different if you’re viewing a single HQ post.

    function wpse99587_single_hq_post() {
        global $post;
        if( is_single() && in_category( 'HQ', $post->ID ) ){
            global $content_width;
            $content_width = 900;
        }
    }
    add_action( 'wp', 'wpse99587_single_hq_post' );
        // I dithered on where to hook this function;
        // if there's a better hook to use, please correct me
    

    This assumes that the $content_width variable is global.

    See the Codex pages for is_single() & in_category() for more information.

  2. To add to @Pat’s answer above. Try to add this to your CSS.

    img {
         width:100%;
        }
    

    Sometimes thats all it takes

Comments are closed.