Forums

Get attachment url in large size not working (4 posts)

  1. winterwisp
    Member
    Posted 9 months ago #

    Hey there,

    I have this in my index.php

    <?php
    	global $wp_query;
    	$postid = $wp_query->post->ID;
    	$imageid = get_post_meta(68, 'Slide 1 image', true);
    ?>
    <img src="<?php echo wp_get_attachment_url ($imageid, 'Medium'); ?>" />

    It's pulling an image url from an image uploaded through custom field template on a particular post. I'm trying to display the medium sized version of the image however its linking to the full size image.

    Does anyone know why this is?

    Any help would be great!

    Thanks!

  2. Fumito Mizuno
    Member
    Posted 9 months ago #

    Hi, winterwisp

    wp_get_attachment_url does not have a size option.
    http://codex.wordpress.org/Function_Reference/wp_get_attachment_url

    please try wp_get_attachment_image.
    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image
    echo wp_get_attachment_image ($imageid, 'medium');

  3. winterwisp
    Member
    Posted 9 months ago #

    Thanks so much for clarifying that. It's definitely pulling the correct image now!

    However, it outputs the entire image code and I was wondering if I could add a custom class to the image?

    Thanks!

  4. winterwisp
    Member
    Posted 9 months ago #

    I figured it out I think.

    I don't fully understand what I did but it works for me and hopefully it helps someone:

    <?php
    	global $wp_query;
    	$postid = $wp_query->post->ID;
    	$imageid = get_post_meta(68, 'Slide 1 image', true);
    ?>
    
    <?php
    	$imageUrl = wp_get_attachment_image_src( $imageid, array(640, 320));
    	echo '<img class="CustomClassGoesHere" src="'; echo $imageUrl[0]; echo '"/> '; ?>

Reply

You must log in to post.

About this Topic

Tags

No tags yet.