Get relative path of mediul sized featured image?
-
Is it possible to show featured image (medium sized) relative URL path (relative to the website root)?
For example, this is what I need “uploads/2014/07/image-600×400.png”
This is what I tried so far:
if ( has_post_thumbnail()) { $medium_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium'); echo $medium_image_url[0]; }
This actually works quite fine, I get path of medium sized featured image, but not relative path, I get it with domain name also, and I need it without domain name.
After that I tried something like this (global wordpress sql data base query) to show relative path of featured image:
global $wpdb; $the_thumbnail_id = get_post_thumbnail_id($post->ID); $the_thumbnail_name = $wpdb->get_var( "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = '$the_thumbnail_id' AND meta_key = '_wp_attached_file'" ); // echo $the_thumbnail_name;
This is also working fine, I get just relative path, but not of “medium” sized image which I need, I get path of “full” sized featured image.
Any help, maybe redesign (some parameter for “medium” size) for second function, or some new function?
Best regards.
- The topic ‘Get relative path of mediul sized featured image?’ is closed to new replies.