简体   繁体   中英

Do I need to create or override custom.js on a Wordpress Child theme?

So, I've created a child theme from the University Wordpress.org theme. Created a new style.css file (which references the parent theme) and have a functions.php that looks like this:

<?php
 add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles',      PHP_INT_MAX);
function enqueue_child_theme_styles() {
wp_enqueue_style( 'university', get_template_directory_uri().'/style.css' );
wp_enqueue_style( 'university', get_template_directory_uri() . '/custom.css'      );
 }

So, that loads great. Except the whole reason for me creating a child theme was so that I could modify 'Camera.js' - which is included in the parent's js file.

The camera.js file includes the following line....

fx : 'random', //'random','simpleFade', 'curtainTopLeft', 'curtainTopRight', 'curtainBottomLeft', 'curtainBottomRight', 'curtainSliceLeft', 'curtainSliceRight', 'blindCurtainTopLeft',

with a whole load of other effects you can choose to apply by putting a new effect name in place of the first random .

All I really want to do is have my child theme have just one of these effects applied without playing with the original Camera.js.

The most obvious way I can think of doing this is duplicating the Camera.js file into my Child Theme folder and modifying it in there. Would that work?

Thanks for any help! Sorry if this has been asked elsewhere, I'm not entirely sure what I'm looking for to answer my question.

You cant over ride js files functionality so what you need to do is dequeue the original from your child theme and enqueue one from your child theme:

eg dequeue script (you need to put in the handle the script was enqueued from)

function remove_script(){
    wp_dequeue_script('script_handle_used_to_enqueue');
    wp_enqueue_script( 'newhandle', get_stylesheet_directory_uri() . '/js/Camera.js');
}
add_action('wp_print_scripts', 'remove_script', 100);

Note the above assumes the js file was enqueued in the standard way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM