This repository has been archived by the owner. It is now read-only.

Child theme includes #1

Closed
yumyo opened this Issue Dec 3, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@yumyo

yumyo commented Dec 3, 2012

Hi, I just created the includes/ directory in my required-starter Child theme.
In there I copied req-scripts.php but the parent's one keep being loaded. Any suggestion?

p.s. Thank you for this piece of work ; )

@ghost ghost assigned neverything Dec 3, 2012

@neverything

This comment has been minimized.

Show comment
Hide comment
@neverything

neverything Dec 3, 2012

Contributor

Hi @yumyo thanks for your question. Regarding includes, WordPress doesn't handle the file overwrites here as these are custom code files and no template files coming from WordPress directly. Maybe my new post makes this a little more clear: http://themes.required.ch/news/template-structure-in-required-foundation-and-required-starter-wordpress-themes/

Instead of overwriting the req-scripts.php file you rather use the WordPress API for script and style handling:

Remove all CSS & JS from parent theme (and child theme too, as they depend on it)

function required_starter_themesetup() {

        // Add the following line to your required_starter_themesetup in your child theme functions.php
    remove_action( 'wp_enqueue_scripts', 'required_load_scripts' );

}
add_action( 'after_setup_theme', 'required_starter_themesetup' );

Only remove certain scripts or stylesheets

In your child theme functions.php file create a function like this:

/**
 * Remove scripts from the parent theme
 */
function child_theme_remove_scripts() {

    // Remove theme-js
    wp_dequeue_script( 'theme-js' );
    wp_deregister_script( 'theme-js' );

    // Remove theme css, removes style.css calls
    wp_deregister_style( 'required-foundation-css' );

}
add_action( 'wp_enqueue_scripts', 'child_theme_remove_scripts', 11 );

It's important to have the priority parameter in the last line, otherwise this function gets called before the parent theme has a chance to register scripts.

Hopefully this answers your question!

Contributor

neverything commented Dec 3, 2012

Hi @yumyo thanks for your question. Regarding includes, WordPress doesn't handle the file overwrites here as these are custom code files and no template files coming from WordPress directly. Maybe my new post makes this a little more clear: http://themes.required.ch/news/template-structure-in-required-foundation-and-required-starter-wordpress-themes/

Instead of overwriting the req-scripts.php file you rather use the WordPress API for script and style handling:

Remove all CSS & JS from parent theme (and child theme too, as they depend on it)

function required_starter_themesetup() {

        // Add the following line to your required_starter_themesetup in your child theme functions.php
    remove_action( 'wp_enqueue_scripts', 'required_load_scripts' );

}
add_action( 'after_setup_theme', 'required_starter_themesetup' );

Only remove certain scripts or stylesheets

In your child theme functions.php file create a function like this:

/**
 * Remove scripts from the parent theme
 */
function child_theme_remove_scripts() {

    // Remove theme-js
    wp_dequeue_script( 'theme-js' );
    wp_deregister_script( 'theme-js' );

    // Remove theme css, removes style.css calls
    wp_deregister_style( 'required-foundation-css' );

}
add_action( 'wp_enqueue_scripts', 'child_theme_remove_scripts', 11 );

It's important to have the priority parameter in the last line, otherwise this function gets called before the parent theme has a chance to register scripts.

Hopefully this answers your question!

@neverything neverything closed this Dec 3, 2012

@neverything

This comment has been minimized.

Show comment
Hide comment
@neverything

neverything Dec 13, 2012

Contributor

Just to let you know @yumyo, I published an article related to your question here: http://themes.required.ch/news/how-are-scripts-and-styles-loaded/

Contributor

neverything commented Dec 13, 2012

Just to let you know @yumyo, I published an article related to your question here: http://themes.required.ch/news/how-are-scripts-and-styles-loaded/

@yumyo

This comment has been minimized.

Show comment
Hide comment
@yumyo

yumyo Dec 14, 2012

Useful, thank you!

yumyo commented Dec 14, 2012

Useful, thank you!

@neverything

This comment has been minimized.

Show comment
Hide comment
@neverything

neverything Dec 14, 2012

Contributor

Thank you for your question, if you have more, keep them coming ;-)

On 14.12.2012, at 17:22, yumyo notifications@github.com wrote:

Useful, thank you!


Reply to this email directly or view it on GitHub.

Contributor

neverything commented Dec 14, 2012

Thank you for your question, if you have more, keep them coming ;-)

On 14.12.2012, at 17:22, yumyo notifications@github.com wrote:

Useful, thank you!


Reply to this email directly or view it on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.