my problem is to set a root variable for images without writing all the path in Wordpress with php. My situation is:
<img src="http://localhost/business/wp-content/themes/enigma-child/images/sottocategorie/animaliDomestici/cane.jpg" class="img-thumbnail img-responsive">
i want this situation ($root=http://localhost/business/wp-content/themes/enigma-child):
<img src="root/images/sottocategorie/animaliDomestici/cane.jpg" class="img-thumbnail img-responsive">
where do I set this root variable in wordpress? there is a way to take the images from the gallery? Thx for answers
Since you are referencing from a child theme the way you dynamically call an image is by using the
get_stylesheet_directory_uri()
function.Eg.
<img class="img-responsive" src="<?php get_stylesheet_directory_uri(); ?>/images/image.png" alt="your image">
For $root as your variable, would be best to insert this as a global variable in your functions.php or header.php . This way you do not modify core code but extend from your child theme.
How do I declare a global variable in PHP I can use across templates?
https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri