• Resolved pk-71

    (@pauljohnknight)


    Hi,

    I’m trying to pull in a specific image from the media library onto a page and I’m using the wp_get_attachment_image() function, but it doesn’t seem to be working.

    The image I wish to use has an id of 142, so in the function I’ve done the following:

    src="<?php wp_get_attachment_image( 142, 'large', false, [] );?>"

    Am I doing this correctly by just adding the ID number in as the 1st parameter? The examples in the docs aren’t particularly informative. I can’t work out why it isn’t working.

    Any help would be really appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    That last parameter is either a string or an array, so it should be '' or array().

    Please define “not working”.

    Thread Starter pk-71

    (@pauljohnknight)

    Hi Steve,

    I changed it to src="<?php wp_get_attachment_image( 142, 'large', false, '' );?>" but it still isn’t working. When I say not working I mean the image doesn’t show in the frontend. All I’m getting is the alt text (the alt text is added in the template file and doesn’t come from the media library).

    Paul

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    <?php
       $result = wp_get_attachment_image( 142, 'large', false, '' );
       print_r( $result );
    ?>

    What do you get?

    Thread Starter pk-71

    (@pauljohnknight)

    I’ve found the problem. I’m missing the echo. A thousand apologies.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Been there. Done that. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pulling In A Specific Image with wp_get_attachment_image()’ is closed to new replies.