thewirelessguy / cornerstone

Cornerstone is a WordPress starter theme based on the Zurb Foundation Responsive Framework. Cornerstone aims to provide a lightweight starter theme that is responsive and SEO friendly that web designers can build great looking websites on.
GNU General Public License v2.0
155 stars 40 forks source link

Improve how CSS and JS is added to the theme. #15

Closed pablopaul closed 10 years ago

pablopaul commented 10 years ago

Split CSS and JS enqueue into two different functions. Make both functions check for existence to enable a child theme to override it if needed (http://codex.wordpress.org/Child_Themes#Using_functions.php).

I did this change because I want to use my own build of foundation in a cornerstone child theme, therefore I do not need the CSS from the cornerstone parent theme.

klongdesigns commented 10 years ago

I had thought of this too, but in the end, added the following in my functions:

function remove_cornerstone_actions() {
    remove_action('wp_enqueue_scripts', 'load_cornerstone_scripts',0);
    remove_action('init', 'Orbit');
    remove_action('init', 'cornerstone_menus');
}
add_action('after_setup_theme','remove_cornerstone_actions', 10);

That allows you to choose what components in the cornerstone parent theme you want to remove. Then you can add your own functions to replace or load what they originally had.

pablopaul commented 10 years ago

Why not follow the WordPress Codex ( = Best Practice ) ?

alana-mullen commented 10 years ago

I'm following WordPress Codex best practice. The example on WordPress Codex uses a function which loads both CSS and JavaScript files (http://codex.wordpress.org/Function_Reference/wp_enqueue_script). Each script/stylesheet has a name so it can individually be removed by a child theme. To remove the Foundation stylesheet you could use the following:

add_action('wp_enqueue_scripts', 'remove_cornerstone_style',50);
function remove_cornerstone_style() {
    wp_dequeue_style( 'foundation_css' );
}
pablopaul commented 10 years ago

I meant here the part of checking the existence of the function in the parent theme

if ( ! function_exists( 'theme_special_nav' ) ) {
    function theme_special_nav() {
        //  Do something.
    }
}

so that a child theme can replace the function.

I think in the end the way I mentioned is a little bit shorter than remove the style/script-registering first (remove_cornerstone_style) and then adding it again with a new function, but the result ist the same ;).

If you do not want to merge the PR feel free to close the ticket @thewirelessguy .

alana-mullen commented 10 years ago

I see now. That makes a lot of sense. I'll start doing the same with other functions. I've merged your whole pull request, though I think people will still end up using wp_dequeue_style or wp_dequeue_script for individual items especially for foundation_init.js as it's easier than rewriting the whole function. This gives people the choice.