Difference between how to set path to the theme folder

‘template_url‘ / ‘template_directory‘ – URL of the active theme’s directory. Within child themes, both get_bloginfo(‘template_url’) and get_template() will return the parent theme directory. Consider echoing get_template_directory_uri() instead (for the parent template directory) or get_stylesheet_directory_uri() (for the child template directory). Source: https://developer.wordpress.org/reference/functions/bloginfo/ the function get_template_directory_uri() is the better one, if you want to support creating child … Read more

Get not the full path

You might want to use the media_media_sideload_image() function. This function will fetch an image from a URL and upload it for you. Take a look into this custom function: function upload_image_from_url($image_url, $post_id, $title) { $img_name = basename ($image_url); global $wpdb; $query = “SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value=”$img_name””; $id = $wpdb->get_var($query); if (is_numeric($id)) { return … Read more

‘posts’ table should not store the absolute image path

Well, after a little research I realized that it is an (inconvenient) feature of WordPress to store the absolute path of the images and other files, something that I completely disagree with. In any case, I discovered this plugin https://wordpress.org/plugins/root-relative-urls/. It does not fix the urls of files already inserted, but it corrects those of … Read more

I can’t load my images from a js file using wp_localize_script

You’re not accessing the value correctly. The 2nd argument of wp_localize_script is the name of a JavaScript object that your data will be added to. In your case it’s wpa_data. This means that the image_path is accessed at wpa_data.image_path: $(function(){ jQuery(document).ready(function() { $(‘#home’).backstretch([ wpa_data.image_path+”home-bg-slideshow1.jpg”, wpa_data.image_path+”home-bg-slideshow2.jpg”, wpa_data.image_path+”home-bg-slideshow3.jpg”, ], {duration: 2000, fade: 750}); }); })