1

I never Enqueued the main stylesheet I'm using on my Wordpress site in the functions.php doc. I just uploaded the stylesheet to the site. Everything works, but I now want to dequeue the stylesheet on a specific page template. How would I go about enqueueing the stylesheet? I'm not sure why my stylesheet works even though I haven't enqueued it.

Any help would be much appreciated. enter image description here

1
  • 1
    Many themes hard-include style.css. Does your header.php file have something similar to <link rel="stylesheet" href="<? bloginfo('stylesheet_url'); ?>" type="text/css" /> Commented Oct 18, 2016 at 19:24

1 Answer 1

2

style.css is a requirement for any theme. Therefore you cannot dequeue it. You can however have a blank (except for the comments) style.css and enqueue another stylesheet for certain templates. To do so you would use wp_enqueue_scripts() like so :

function my_enqueue_style() {
  if ( is_front_page() ) {
    wp_enqueue_style( 'mystyle', get_stylesheet_directory_uri() . '/mystyle.css' );
  }
}

add_action( 'wp_enqueue_scripts', 'my_enqueue_style' );
4
  • 1
    +1, but what about get_stylesheet_directory_uri()
    – prosti
    Commented Oct 18, 2016 at 20:16
  • good point- changed it.
    – mantis
    Commented Oct 18, 2016 at 20:28
  • Thank you for the answer. Common sense tells me I should Include this function near the top of my template code. Is that correct? Anywhere specifically it should go? Commented Oct 18, 2016 at 20:56
  • You're welcome :) Actually it should go in functions.php of you theme.
    – mantis
    Commented Oct 19, 2016 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.