我想在特定页面上运行特定js。即:wwww.custom.com/english/
我尝试了以下两个代码(header.php和functions.php),但它们都不起作用。
代码1:
<script>
if(location.pathname=="/english/")
script.src = /js/custom.js;
</script>
Run Code Online (Sandbox Code Playgroud)
代码2:
function my_scripts() {
if( is_page( array( 'about-us', 'contact', 'management' ) ){
wp_enqueue_script( 'script-name', 'path/to/example.js', array(), '1.0.0', true );
}
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
Run Code Online (Sandbox Code Playgroud)
标题一根本不显示,也没有错误。functions.php是语法错误。
有什么建议么?多谢
PS:我正在使用WordPress。