Answer the question
In order to leave comments, you need to log in
Why can't check condition in functions.php file in wordpress?
Hello! I want to connect scripts for Yandex maps to work on certain wordpress pages using the functions.php configuration file. I write a condition like this:
if(is_home() || is_page(1825)) {
function yandex_api(){
wp_enqueue_script( 'yandexmap', get_stylesheet_directory_uri() . '/js/ya-map.js');
wp_enqueue_script( 'yandexapi', get_stylesheet_directory_uri() . '/js/yandex-maps.js');
}
add_action( 'wp_enqueue_scripts', 'yandex_api' );
}
Answer the question
In order to leave comments, you need to log in
Rewrite the function, the check should be done right inside it:
function yandex_api() {
if ( is_home() || is_page( 1825 ) ) {
wp_enqueue_script( 'yandexmap', get_stylesheet_directory_uri() . '/js/ya-map.js' );
wp_enqueue_script( 'yandexapi', get_stylesheet_directory_uri() . '/js/yandex-maps.js' );
}
}
add_action( 'wp_enqueue_scripts', 'yandex_api' );
While processing the functions.php file, it is not yet known what page it is.
Therefore, there is no point in doing such checks.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question