Visualizzazione 2 filoni di risposte
Visualizzazione 2 filoni di risposte
- Devi essere connesso per rispondere a questo topic.
Email: info@wpitaly.it
Home › Forum › Problemi Vari con WP › Condizionare add_action
Buongiorno,
sono sono un vecchio programmatore ASP che si accinge a conoscere questo grande CSM e giochicchiando un po’ con il codice ho la seguente esigenza vorrei aggiungere un js ad una pagina e non a tutto il sito quindi ho registrato una funzione in functions.php nel tema child:
// CARICA IL JS FIGLIO
add_action( ‘wp_enqueue_scripts’, ‘child_add_scripts’ );
function child_add_scripts() {
wp_register_script(
‘funzioni’,
get_stylesheet_directory_uri() . ‘/js/Funzioni.js’,
false,
‘1.0’,
false
);
wp_enqueue_script( ‘funzioni’ );
}
fin qui tutto ok, ma vorrei che questo script venisse caricato solo in una determinata pagina quindi ho provato a condizionare add_action nel seguente modo:
if ( is_page(‘test’) ){
add_action( ‘wp_enqueue_scripts’, ‘child_add_scripts’ );
}
, ma non funziona.
Cosa ho mancato dove sbaglio 1000 grazie
add_action( ‘wp_enqueue_scripts’, ‘child_add_scripts’ );
function child_add_scripts() {
wp_register_script(
‘funzioni’,
get_stylesheet_directory_uri() . ‘/js/Funzioni.js’,
false,
‘1.0’,
false
);
if ( is_page( ‘test’ ) ){
wp_enqueue_script( ‘funzioni’ );
}
}
1000 grazie
WPItaly - Copyright Creative Commons: CC BY-NC-SA 4.0