Support » Themes and Templates » wp_get_attachment_url not showing anything

  • I’ve been going over all of the documentation and I can’t figure out why this isn’t working:

    echo wp_get_attachment_url($post_id);

    This works:

    echo get_attachment_link($post_id, 'medium');

    Is wp_get_attachment_url deprecated? I don’t want the attachment’s page. There’s no mention of a replacement function to return the full URL to the attached image.

Viewing 3 replies - 1 through 3 (of 3 total)
  • esmi


    Forum Moderator

    I tried that too – comes up blank.

    I’m trying to modify the output of the Favorites Post plugin. Here is their code with my additions (just testing it now):

    if ($favorite_post_ids):
            foreach ($favorite_post_ids as $post_id) {
                $p = get_post($post_id);
                echo "<li>";
                echo "<a href='".get_permalink($post_id)."' title='". $p->post_title ."'>" . $p->post_title ."</a> ";
    echo wp_get_attachment_url($post_id);
    echo get_attachment_link($post_id, 'medium');

    The output of this is correct except the wp_get_attachment_url is blank.


    I get the title of the post (from the original plugin) then

    I even tried using explicitly using 84 instead of $post_id and that did the same thing.

    This also doesn’t work for me:

    echo get_attached_file($post_id);

    nor does

    echo get_attached_file(84);

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_get_attachment_url not showing anything’ is closed to new replies.