WordPress.org

Ready to get started?Download WordPress

Forums

How to get the permanent link of featured image? (1 post)

  1. acjdesigns
    Member
    Posted 2 months ago #

    I'm wondering what is the PHP code to get the permanent link of a featured image in a post. I can't use just the image link because each post has a different featured image. Any help is highly appreciated!

    Currently I'm trying:

    function get_url(){
    	$thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), array($featured_image_width,$featured_image_height));
    	$url=$thumb['0'];
    	wp_enqueue_script('post-tiles',$plugin_url.'/post-tiles-frontend.js');
    	wp_localize_script('post-tiles', 'get_url', $url);
    }
    add_action('wp_enqueue_scripts', 'get_url');

    For some reason, the image is showing up as "null" on the page. Did I have to do something extra to load the $url variable as one that can be used in the javascript? Some examples have arrays, but I don't know why I would use an array when I have only to pass the variable.

Reply

You must log in to post.

About this Topic