Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, you want in parent theme have a function, that hooks your JS files and in a child theme only add JS files?</p> <p>Your code is sort of messy. I explain</p> <ol> <li>scripts should be hooked into <code>wp_enqueue_scripts</code>, not <code>init</code></li> <li><code>wp_enqueue_script</code> does not return any value (not even NULL :-D), so assigning it to a variable is useless</li> <li>Pay attention to your naming of filter, functions <code>add_filter</code> and <code>apply_filters</code> "work" together, so their first parameter should be same</li> </ol> <p>And here is code, that I assume, you wanted, in the parent theme, there is created a function, that do the enqueueing, and through child theme, you only set an array of javascript files to be hooked and enqueued.</p> <pre><code>function st_header_scripts() { /** * 'jquery' has FALSE value, since it is registered in wordpress and you do not need an url */ $js_files = array( 'jquery' =&gt; false, 'custom' =&gt; get_bloginfo('template_url') ."/javascripts/app.js", 'superfish' =&gt; get_bloginfo('template_url') ."/javascripts/superfish.js", 'formalize' =&gt;get_bloginfo('template_url') ."/javascripts/jquery.formalize.min.js" ); /** * Here you create a variable with a possibility to be filtered * The first argument is your custom name of your filter * The second argument is a variable which might be modified with filter and assigned to the $javascripts variable */ $javascripts = apply_filters('header_javascripts', $js_files); /** * Here you just enqueue your scripts */ if(false != $javascripts) foreach($javascripts as $name =&gt; $uri) if(!$uri) wp_enqueue_script($name); else wp_enqueue_script($name, $uri, array('jquery'), '1.2.3', true ); } add_action('wp_enqueue_scripts', 'st_header_scripts'); /** * A callback for a filter `header_javascripts` * @param array $original_js array of JS files from parent theme * You can either add JS into array or create and return new array */ function children_theme_js($original_js) { //adding to original array $original_js[] = 'jquery-ui-core'; //not enqueueing JS from parent theme //$original_js = array(); //$original_js['script'] = 'I-am-the-url'; //you need to return an array into the filter return $original_js; } add_filter('header_javascripts','children_theme_js'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload