• Resolved unconquered

    (@unconquered)


    I’ve created few custom image sizes using add_image_size() Basically, all I want to do is:

    • display whatever image size I specify
    • learn some way to call a single custom image size url

    I used a method after looking around and searching which involves get_intermediate_image_sizes(); But it ends up displaying every size including the thumbnail size 150×150

    Lets say I have
    add_image_size( ‘hd’, 1280, 720, true );

    I would want it to display on my attachment page like – High Definition: 1280×720
    with code being something like this High Definition:<a href="link to image size">1280x720</a>
    Any reference I should look up in the codec?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m not entirely sure what you’re asking but if you know the image size names you can just call most the image functions with that size passed as a parameter. For example, wp_get_attachment_link() accepts size as a parameter, so if I wanted to link to a specific images thumbnail I could say:

    // IF on the Attachment Page $attachment_id would be $post->ID
    wp_get_attachment_link( $attachment_id, 'thumbnail' );

    I would still need to get the attachment image ID but if we’re viewing it on the attachment page already, $attachment_id would be the $post->ID.

    Thread Starter unconquered

    (@unconquered)

    @howdy_mcgee thanks a lot! that’s exactly the function I was looking for. To be specific

    echo wp_get_attachment_link( $id, '' , false, false, 'My link text' );

    Works perfect, and call the attachment id using get_the_ID();

    echo wp_get_attachment_link( get_the_ID(), '' , false, false, 'My link text' );

    Above is the solution, thanks again @howdy_mcgee

    Thread Starter unconquered

    (@unconquered)

    EDIT: The above doesn’t link to the size specific attachment, instead it displays the size specific attachment and links to the full size.

    I ended up going with wp_get_attachment_image_src()

    <?php $the_image_link= wp_get_attachment_image_src( get_the_ID(), 'mycustomsize' ); ?>
    Custom Size :<a href="<?php $the_image_link[0]; ?>"> View </a>

    It seems to again link to the fullsize/default stuff again

    EDIT Fixed.
    It seems to work when done in one go:

    <?php $the_image= wp_get_attachment_image_src( get_the_ID(), 'myCustomsize' );
    		$img_size_url=$the_image[0];
    echo '<a href='.$img_size_url.'>View Custom size</a>'; ?>
    • This reply was modified 7 years, 9 months ago by unconquered.
    • This reply was modified 7 years, 9 months ago by unconquered.
    • This reply was modified 7 years, 9 months ago by unconquered.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying only specific Custom Image Size as links?’ is closed to new replies.