Answer the question
In order to leave comments, you need to log in
How to set the path to the image generated from the javascript code (cms Wordpress)?
Hello. Here is the code for generating carousel arrows (owl carousel2) from a javascript file
$('.feedback__carousel').owlCarousel({
loop: true,
nav: true,
smartSpeed: 900,
navText: ['<img src="img/arrow-left.png" alt="Стрелка влево">','<img src="img/arrow-left.png" alt="Стрелка вправо">'],
});
// const arrSrc = "<? echo bloginfo('template_url'); ?>/";
const arrSrc = "<? echo bloginfo('template_url'); ?>/";
console.log(arrSrc);
$('.feedback__carousel').owlCarousel({
loop: true,
nav: true,
smartSpeed: 900,
navText: ['<img src="' + arrSrc + 'img/arrow-left.png" alt="Стрелка влево">','<img src="' + arrSrc + 'img/arrow-left.png" alt="Стрелка вправо">'],
});
<img src="<? echo bloginfo('template_url'); ?>/img/arrow-left.png" alt="Стрелка вправо">
Answer the question
In order to leave comments, you need to log in
Hello.
The easiest way to write the path in full /wp-content/themes/ПАПКА_ТЕМЫ/img/arrow-left.png
If using WordPress tools is to pass the path using the wp_localize_script function .
More or less like this:
add_action( 'wp_enqueue_scripts', 'action_function_name_7714', 99 );
function action_function_name_7714(){
wp_localize_script( 'jquery', 'mytheme', array(
'template_url' => get_template_directory_uri(),
) );
}
$('.feedback__carousel').owlCarousel({
loop: true,
nav: true,
smartSpeed: 900,
navText: ['<img src="' + mytheme.template_url + '/img/arrow-left.png" alt="Стрелка влево">','<img src="' + mytheme.template_url + '/img/arrow-left.png" alt="Стрелка вправо">'],
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question