Skip to content

Instantly share code, notes, and snippets.

@grappler
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grappler/3d6b46cecdf85b490604 to your computer and use it in GitHub Desktop.
Save grappler/3d6b46cecdf85b490604 to your computer and use it in GitHub Desktop.
<?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
Copy link

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