If you use wp_enqueue_style(), with your function, you could call the function from the page (single.php etc.) … pass a string through with the page name, use that in the function to decide which style you are enqueuing. This will then load the script in the head in the correct manner.
https://developer.wordpress.org/reference/functions/wp_enqueue_style/
Eg.
// In single.php
enqueue_my_script('single');
//In functions.php
function enqueue_my_script($page = null){
if($page === 'single') {
add_action( 'wp_enqueue_scripts', 'single_styles');
}
}
function single_styles() {
wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css', array(), null, null);
}
I’m pretty sure something like that should work how you want it to, though it is nearly 2am for me!
Related Posts:
- how to add version of style.css in wordpress
- How can I version the main CSS file?
- How to set two different themes on one WordPress? (Desktop vs. Mobile)
- I’m trying to add an image in my CSS
- How to use scss in wordpress theme?
- How to automatically highlight syntax of code in a post?
- How to add the main style.css to my index.php?
- The style.css stylesheet doesn’t contain a valid theme header
- Getting rid of unused css directives [closed]
- Exclude stylesheet from admin
- Change Theme from Plugin based on query_vars
- Change logo on each page of University Hub theme [closed]
- How do I copy my Parent Templates to my Child Templates?
- Theme information in style.css being corrupted
- How do you create a custom WPTouch theme?
- How to start learning CSS and theme development?
- how to remove padding from left and right side? [closed]
- 404 Error while accessing the font files
- How to load parent theme style.css?
- Child Style.css not overriding parent theme style located in assets/css/main.css
- Creating new templates in child themes breaks layout
- X-Axis of Site is Messed Up Because it is in Hebrew
- Style the archives/category sidebar widget via theme
- Custom CSS doesn’t work in edit mode
- Remove transparancy in Sydney theme’s headerimage
- How can I add class to every quote element?
- Twenty fifteen theme – change responsive menu condition
- CSS Start Fresh option on; main.css still being loaded [closed]
- Port existing Bootstrap site to WordPress?
- How to style the post previews/links without it affecting the main posts?
- Different logo on homepage
- Finding and disabling ‘rogue’ stylesheet from header: Source Sans Pro
- Cannot apply custom css to IE in the theme
- Plugin and themes are adding the same stylesheets
- Child theme’s stylesheet cannot load [closed]
- Theming global variables – initializing in index.php but using in header.pho
- Is it good practice moving the main stylesheets after the plugin styles?
- What Generated Classes and IDs That Is Always Used On All Themes?
- Understanding the theme details in style.css
- Passing dynamic options from backend to frontend
- Re-skinning Site
- Getting a ‘slide down’ js panel implemented within WP
- Calling external Libraries in WordPress
- Need a theme that let the posted content stretched maximum width [closed]
- What’s the default order used by WordPress to load CSS files?
- The requested theme does not exist. Stylesheet is missing – error after changing style.css name to my-styles.css in wp child theme?
- How to trace and resolve a theme problem such as flickering links in WordPress? [closed]
- On a Https site, Css and Js Url are back to http after redirect the site
- How to integrate JSS to WordPress
- Why submenu item’s background color is not changing by css?
- Cannot figure out what element header color is in wordpress theme [closed]
- Increase content area width in TwentyFourteen [closed]
- Using Grunt and keeping theme comments
- header.php-tweak: How to do that getting Meta-Slider into the header-center?
- Display Headings on Index page in different font sizes
- Event Organiser breaks the theme [closed]
- how would I change background color of a theme using a plugin?
- Date based CSS/theme
- WordPress doesn’t recognise created theme
- Menu items do not “open” when mouse hover over them?
- My blog suddenly can’t find my stylesheet?
- WP Nanoplex 1.0.3 malfunction
- Whitespace between logo and site title in Twenty Twenty-Two
- CSS appears to not work on any WordPress theme
- removing side space between para and container on generatepress?
- How can I modify the CSS only for the search results page of WordPress?
- Enqueue All Stylesheets Found In a Theme Folder
- How Can I Disable WordPress Theme Self-Update?
- Theme CSS missing completely
- WordPress 404 on style.css but not on all pages
- how make wp include urls as https?
- Own Theme custom CSS does not display in editor but works in page
- style.css of my custom theme is not being applied at all
- Custom CSS is overwritten by WordPress?
- CSS in child theme isn’t working properly
- WordPress loads old style.css, then loads current one
- Strange Theme Error – parent style occasionally showing though child theme
- TwentyFourteen Theme : Changing grid layout
- Using two stylesheets for mobile compatibility
- Featured images are cropped on index and post page
- EM in CSS different size on wordpress then elsewhere [closed]
- Orion theme (from theme forest) [closed]
- How do I block a subdirectory from WordPress theming?
- div having different appearances in different themes
- Customising a theme
- Blog shows up without Theme/CSS styles
- How to Hide Blog Post Author?
- How can i limit wordpress post title characters in sidebar?
- I can’t install theme: theme install failed
- How can I either move the nav bar down or create more space for the header? Theme – Ajaira
- Commenting in CSS (//) equals “none”? [closed]
- theme 2016 – customize css – nothing happens
- Help with responsive theme styling issue
- How to change the standard width of a page
- Theme install failed
- How can i remove footer credit text
- How to make a page extend full screen [closed]
- Help with Divi logo not appearing for 10s
- Custom Theme Additonal CSS “” are transformed to “>” and “<”
- How to remove pop up on website (css changes not visible)?