Inherit scripts from parent to childtheme

Thats because parent theme using get_stylesheet_directory_uri() to call script. By this function it is searching for file in your child theme folder (bcause child theme’s style.css is using by active theme) where no such files present. This function search those theme folder whose style.css file is using in active theme. Right now your child theme … Read more

Make a script work within a page

I think both external CSS & JavaScript files should be added to your active theme functions.php file into function which implements action wp_enqueue_scripts. It should looks like example code below: <?php // … function themename_enqueue_scripts() { // … wp_enqueue_style(‘themename-slider-style’, ‘//scd01.bcnshop.com/ca/widgets/generate-css/1815/4150.css’, false ); wp_enqueue_script(‘themename-slider-js’, ‘//scd01.bcnshop.com/ca/widgets/generate-js/1815/4150.js’, array(‘jquery’) ); // … } add_action( ‘wp_enqueue_scripts’, ‘themename_enqueue_scripts’ );

How can I leverage browser cache for minified JS or minified CS files?

Yeah, you can do leverage browser caching for minified js & css files same as we do for other files. <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpg “access 1 year” ExpiresByType image/jpeg “access 1 year” ExpiresByType image/gif “access 1 year” ExpiresByType image/png “access 1 year” ExpiresByType text/css “access 1 month” ExpiresByType text/html “access 1 month” ExpiresByType … Read more

WordPress load-scripts.php not loading

/** * add script * * https://developer.wordpress.org/reference/functions/wp_enqueue_script/ */ function youplugin_add_frontend() { // js wp_enqueue_script(‘youplugin-js’, get_template_directory_uri() . ‘/js/scripts.js’, array(‘jquery’), 0.1, true); } // add script add_action(‘wp_enqueue_scripts’, ‘youplugin_add_frontend’);

Headless wp with react. How to handle routes?

You will need to add react-router-dom with npm or yarn. Once you add those, you will need to import some modules into your React app. You will need BrowserRouter, Route, NavLink, & withRouter. BrowserRouter is to be on the outmost parent Component that manages the history API. Ideally, you would just put your <App /> … Read more

Add crossorigin to SCRIPT tag

script_loader_tag or script_loader_src filters are there to let you tweak the HTML of the script easily so you can add custom attributes: add_filter(‘script_loader_tag’, function($tag, $handle){ switch ( $handle ) { case ‘foo’: $tag = preg_replace( ‘/src=[\’|”|]/i’, ‘crossorigin $0’, $tag ); break; } return $tag; }, 10, 2); To avoid conflicting with other plugins, pass unique … Read more

Javascript asset not enqueuing with the rest

Your second wp_enqueue_script() contains the same handle (the same ID) as the first wp_enqueue_script(). The handle is the ID by which a registered script is known to WordPress internally. If you use this ID a second time, the second script won’t be registered. A working example could be this one: <?php add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles_and_scripts’ ); … Read more

How to display/hide accordion? [closed]

That uses bootstraps data-toggle first make sure you have included the proper scripts and css for this usually its just these 4 which should be located in your header if its not included already. <meta name=”viewport” content=”width=device-width, initial-scale=1″> <link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css”> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> <script src=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js”></script> then you can just the correct classes to the image … Read more

Homepage js is conflicting with js of plugin of other page

Put it in an if clause to only load on front page: if (is_front_page()){ // you could also try is_home() //or is_page($the_id_of_home_page = 555) If you know the id of the home page wp_register_script(‘java1’, get_template_directory_uri() . ‘/js/cr-scroll.js’, array( ‘jquery’ )); wp_enqueue_script( ‘java1’ ); } or remove it on a specific page: function remove_scroll_js(){ if (is_page($the_id_of_that_page_lets_say … Read more