Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cdsalmons/dffd7f6b3cdb656d357b to your computer and use it in GitHub Desktop.
Save cdsalmons/dffd7f6b3cdb656d357b to your computer and use it in GitHub Desktop.
Look for a stylesheet in a WP child theme or theme before loading a default plugin stylesheet.
//figure out which css to load
if(file_exists(get_stylesheet_directory() . "/pluginname/frontend.css"))
$css_url = get_stylesheet_directory_uri() . "/pluginname/frontend.css";
elseif(file_exists(get_template_directory() . "/pluginname/frontend.css"))
$css_url = get_template_directory_uri() . "/pluginname/frontend.css";
else
$css_url = plugins_url('css/frontend.css',dirname(__FILE__) );
//load it
wp_enqueue_style('pluginname-frontend', $css_url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment