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.
1 Answer
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' );
-
1
-
-
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.– mantisCommented Oct 19, 2016 at 8:03
style.css
. Does yourheader.php
file have something similar to<link rel="stylesheet" href="<? bloginfo('stylesheet_url'); ?>" type="text/css" />