0

How do I set a specific size for my image? For example, I want my image size always be "800px" width and "600px" height. When I upload the any images, it should be that size. It should be responsive too. For the upload manager, if I upload the images is too large, I can crop it ....

 <section class="container-wrap">
 <article class="post-wrap">
    <?php

        $args  = array('post_type' => 'journals');
        $query = new WP_Query($args);

        while($query -> have_posts()) : $query -> the_post();

    ?>

    <a href="<?php the_permalink(); ?>" class="post-img">
        <img width="20" height="20"src="<?php echo(types_render_field('artwork', array('raw' => true) )); ?>">
    </a>
    <header>
        <span class="post-date"><?php echo(types_render_field('date', array('format' => 'm.d.Y') )); ?></span>
        <a href="<?php the_permalink(); ?>" class="post-title">
            <h3><?php echo(types_render_field('title', array('raw' => true) )); ?></h3>
        </a>
    </header>

    <?php endwhile; ?>

</article>
</section>

1 Answer 1

0

Use Add_image_size in your functions.php

function theme_sizes(){
 add_image_size( 'custom-size', 800, 600);
}

in your code above use something like:

wp_get_attachment_image( 42, 'custom-size' );

Add_image_size adds a new option when you upload an image, which will then crop the image to the dimensions you need, so you would have thumbnail, medium, full size and your custom-size

4
  • What does the 42 mean? When I upload an image the size is not 800 by 600. Oct 16, 2015 at 12:00
  • 42 is the id of the post which has the image, you can change that to $post->ID Oct 16, 2015 at 12:01
  • do you mean the post id from the page im uploading image? Oct 16, 2015 at 12:02
  • yes, $post->ID will do that for you Oct 16, 2015 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.