- This topic has 9 replies, 2 voices, and was last updated 2 years ago by David.
November 6, 2019 at 1:44 am #1054562Marcel
I would ask what if there is an option to disable the style sheet for certain pages and posts. I use a child theme, and I would like to use custom HTML and CSS in some pages and posts. Even I use the Simple CSS plugin on those pages and apply custom CSS, the final result is weird. I know for sure there is a solution for that, please just give me a short guide. Thank you!November 6, 2019 at 5:30 am #1054725DavidStaffCustomer Support
the correct way would be to save the styles in a separate style sheet and use the
But this would require you to add a condition to where the code should be loaded.
Simplest method would be to use a Hook element and add a link to the style sheet in the WP_head for those specific pages:
<link rel="stylesheet" id="my-custom-style-sheet" href="full_url_to_my_custom_styles" type="text/css" media="all">November 6, 2019 at 9:27 am #1055099Marcel
David, thank you! So, to understand I should create a custom CSS file and store it on my child theme folder, where function.php and style.css already exist and name it according to the example given above (my-custom-style-sheet.css)? Image attached.
And, the full URL to my-custom-style-sheet would be: my-website.com/wp-content/themes/generatepress_child/my-custom-style-sheet.css?November 6, 2019 at 9:40 am #1055113DavidStaffCustomer SupportNovember 8, 2019 at 2:28 am #1056665Marcel
Please guide me on this puzzle:
– should I put also my HTML into a Hook element and add a link to the style sheet in the WP_head for a specific page
– just add a link to the style sheet in the WP_head for a specific page and put my HTML into that page (using a custom HTML Gutenberg block, for instance…)? Image here.
Thank you!November 8, 2019 at 2:36 am #1056671DavidStaffCustomer SupportNovember 8, 2019 at 3:06 am #1056698Marcel
Perfect. It is working. Now, if I would to use wp_enqueue_scripts (the correct way), should I include it on my function.php or using a hook? Could I have a hypothetical snippet from your side, let say for a style sheet with the ID=”my-custom-style-sheet” and adding a condition to where the code should be loaded, let say for the page with ID= 101? Thank you!November 8, 2019 at 3:30 am #1056725DavidStaffCustomer Support
wp_enqueue_scripts would go in the function.php. Tom provides an example of conditional enqueue here:November 12, 2019 at 9:45 pm #1061317Marcel
Thank you, David. Should I first use “wp_dequeue_style” first, for better results or it is not necessary?November 13, 2019 at 5:25 am #1061652
- You must be logged in to reply to this topic.