Aşağıdaki gibi bir kod yazıp JS dosyasını çağırdığımda sitede çeşitli sorunlar yaşıyorum, cache..vs düzgün çalışmıyor.
function wpb_adding_scripts() {
wp_register_script('dm-add_script', trailingslashit(get_stylesheet_directory_uri()).'add.js', false, GRIDLOVE_THEME_VERSION, 'screen');
wp_enqueue_script('dm-add_script');
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );Gridlove temasını kullanıyorum ve tema child içerisinde .css'i şu fonksiyon içe çağırıyor, beki buna js eklemek işi çözer. PHP bilmediğim için ekleyemiyorum.
function gridlove_child_theme_setup(){
add_action('wp_enqueue_scripts', 'gridlove_child_load_scripts');
}
function gridlove_child_load_scripts() {
wp_register_style('gridlove_child_load_scripts', trailingslashit(get_stylesheet_directory_uri()).'style.css', false, GRIDLOVE_THEME_VERSION, 'screen');
wp_enqueue_style('gridlove_child_load_scripts');
}Temanın kendisi ilse js seçmek için şu fonksiyonu kullanıyor:
/* Load frontend scripts */
add_action( 'wp_enqueue_scripts', 'gridlove_load_scripts' );
/**
* Load scripts on frontend
*
* It just wrapps two other separate functions for loading css and js files
*
* @return void
* @since 1.0
*/
function gridlove_load_scripts() {
gridlove_load_js();
}
/**
* Load frontend js files
*
* @return void
* @since 1.0
*/
function gridlove_load_js() {
//Load comment reply js
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
//Check if is minified option active and load appropriate files
if ( gridlove_get_option( 'minify_js' ) ) {
wp_enqueue_script( 'gridlove-main', get_parent_theme_file_uri( '/assets/js/min.js' ), array( 'jquery', 'jquery-masonry', 'imagesloaded' ), GRIDLOVE_THEME_VERSION, true );
} else {
$scripts = array(
'magnific-popup' => 'magnific-popup.js',
'fitvids' => 'fitvids.js',
'autoellipsis' => 'autoellipsis.js',
'sticky-kit' => 'sticky-kit.js',
'owl-carousel' => 'owl-carousel.js',
'objectfit-images' => 'ofi.js',
'main' => 'main.js'
);
foreach ( $scripts as $id => $script ) {
wp_enqueue_script( 'gridlove-'.$id, get_parent_theme_file_uri( '/assets/js/'. $script ), array( 'jquery', 'jquery-masonry', 'imagesloaded' ), GRIDLOVE_THEME_VERSION, true );
}
}
wp_localize_script( 'gridlove-main', 'gridlove_js_settings', gridlove_get_js_settings() );
}Ben şimdi yeni bir fonksiyon tanımlamak yerine var olan fonksiyonlardan hangisini nasıl kullanarak ilk kodlarda belirttiğim
add.js dosyasını çağırabilirim?