Skip to content

Instantly share code, notes, and snippets.

@grappler grappler/version-1.php

Last active Aug 29, 2015
Embed
What would you like to do?
<?php
add_action( 'wp_enqueue_scripts', 'grappler_scripts' );
function grappler_scripts() {
wp_enqueue_style( 'grappler-style', get_template_directory_uri() . '/output/style.css' );
if ( is_child_theme() ) {
wp_enqueue_style( 'grappler-child-style', get_stylesheet_uri() );
}
}
<?php
add_action( 'wp_enqueue_scripts', 'grappler_scripts' );
function grappler_scripts() {
if ( is_child_theme() ) {
wp_enqueue_style( 'grappler-child-style', get_stylesheet_uri() );
wp_enqueue_style( 'grappler-style', get_template_directory_uri() . '/output/style.css' );
} else {
wp_enqueue_style( 'grappler-style', get_stylesheet_uri() );
}
}
add_action( 'stylesheet_uri', 'grappler_stylesheet_uri', 10, 2 );
function grappler_stylesheet_uri( $stylesheet_uri, $stylesheet_dir_uri ) {
if ( ! is_child_theme() ) {
$stylesheet_uri = $stylesheet_dir_uri . '/output/style.css';
}
return $stylesheet_uri;
}
@justintadlock

This comment has been minimized.

Copy link

justintadlock commented Nov 2, 2014

Assuming this code is happening the main [parent] theme:

<?php

add_action( 'wp_enqueue_scripts', 'grappler_scripts' );

function grappler_scripts() {

    if ( is_child_theme() ) {
        wp_enqueue_style( 'grappler-style', get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'grappler-child-style', get_stylesheet_uri() );
    } else {
        wp_enqueue_style( 'grappler-style', get_stylesheet_uri() );
    }
}

Or, a simpler version:

<?php

add_action( 'wp_enqueue_scripts', 'grappler_scripts' );

function grappler_scripts() {

    if ( is_child_theme() ) {
        wp_enqueue_style( 'grappler-parent-style', get_template_directory_uri() . '/style.css' );
    }

    wp_enqueue_style( 'grappler-style', get_stylesheet_uri() );
}

Some notes:

  • I don't see any reason to use output/style.css at all here. Just stick the code in your main style.css.
  • If for some odd reason, you had to use output/style.css, using the filter would be preferred to me.
  • Child theme style.css should load second to override parent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.