Check the current template in your callback. This is a post meta field named _wp_page_template
.
add_action("wp_enqueue_scripts", function()
{
// This stylesheet is used on *every* page
wp_register_style("sitewide", get_template_directory_uri() . "/assets/sitewide.css");
wp_enqueue_style("sitewide");
if ( ! is_singular() )
return;
$template = get_post_meta( get_the_ID(), '_wp_page_template', TRUE );
// now enqueue further stylesheets depending on the current template
});
Related Posts:
- Why I can’t add a CSS style in this WordPress theme?
- What can I hook into after_setup_theme?
- Advantages of using instead of wp_enqueue_style()?
- How to add dynamic inline style?
- Dequeue a style file which is making website load slow!
- Stylesheet not linking
- Theme Loading Into Dashboard
- Font Awesome 5 Free – far working but fas is not? [closed]
- Having issue with WordPress wp_enqueue_style
- theme style is applied on the dhasboard rather than the website
- How important is it to enqueue a theme’s stylesheet?
- The the_post_thumbnail without srcset?
- after_setup_theme always runs
- Using classes instead of global functions in functions.php
- WordPress API Menu/Submenu Order
- What WP folder can I use to write files to?
- Setting multiple default background images?
- How to make a theme with more than one CSS file?
- register_sidebar ignores ‘id’ and ‘class’
- Display a different theme for not logged-in users
- Best practice (forward compatibility) for theme options
- Add colors to existing color palette without replacing it
- Single Page WordPress Theme – Using page templates
- Returning Variables back into a template
- new theme permissions don’t allow me to edit
- Which theme foundry has clean coded themes, where code is poetry [closed]
- What page should I use for a contact form?
- Retrieve data using wpdb to use for customizer controls
- How can a Theme Contain no Header File or Footer File?
- Version control for both Vagrant config and themes being developed [closed]
- Some translations do not work in my template class
- WordPress not registering Theme Customization Section
- How to remove a file included in parent theme with locate_template() via child theme?
- WP 3.1 upgrade breaks AutoFocus+ theme
- How to add infinite scroll?
- get_option in header.php not returning value from customizer
- Internal error 500 accessing Theme > Customize
- How to make theme elements customizable in wordpress?
- Theme Development: Starter Content after hook
- Change locale by detecting viewer’s browser language setting and let them choose prefered language after
- Why is it needed to enqueue parent stylesheet in child theme?
- Is there any WordPress theme for Self Storagae just like Spacer [closed]
- Customizer: save setting/control content to post/page
- WordPress Unite Theme: Footer isn’t sticking [closed]
- Is accessing theme and using customizer GPL distribution?
- How to enqueue javascript for WP Customize options sidebar?
- WordPress 500 Internal server error when activating custom theme [closed]
- Customize how a WordPress theme looks like in the Theme Selector
- How to set a page as homepage in stead of the newspages?
- Widget Option is Missing
- WordPress Theme Validator?
- How do I use a color from theme options?
- If you were to start using a WordPress framework today, which one would you use? [closed]
- Template for landing pages
- Is it possible to have a theme that uses only one single page?
- underscores use of the article element on the page template
- Ideal inline dynamic CSS injection
- Plugin does not work in custom theme
- html5-reset theme does not show the image [closed]
- How to include a file only on dashboard widgets page?
- Adding a gallery to my first theme
- Are seven additional image sizes are too many?
- What exactly is “wordpress theming”? [closed]
- I have WordPress setup on primary domain, how do I set it up on its subdomain using the same database?
- Valid SQL query not returning results
- Change Image Sizes for Mobile Theme
- Recommended sidebar / content widths
- Converting a theme to a child theme in a network
- Why is the `if else` not working?
- What is the difference between Twenty eleven & roots framework?
- Is there a list of default generated Gutenberg block CSS? Unable to align video blocks
- How to change listing type permlink?
- Adding popup support to the theme
- Calling a WP Plugin Function’s Variable in Theme Template [duplicate]
- How to make updatable custom WordPress theme?
- How can I access variables from theme in child theme? [closed]
- Local variable name in setup_postdata()
- Creating a Single Page Theme correctly
- How to display home page last modified date in anywhere of wordpress theme?
- Is it possible to echo a woocommerce prouct attribute discription?
- Child theme menu not appearing in Twenty Seventeen
- How do I remove header/page-title image in farvis theme? [closed]
- Using wp_add_inline_style Inside a Template File
- How to link post image to post link?
- WordPress Twenty-Fourteen: How to Remove Home Page Header Image from Other Pages
- How to dowload and edit content of a website
- On wordpress, how do i require specific dimensions from user uploads only
- WordPress Theme Developments – Start from another theme
- Slider should be display in home template [closed]
- Modify comments_popup_link output
- Can you create a custom page with content in the center already defined?
- How to migrate the menu from the site on my own theme in WordPress?
- How Does One Create a Global Variable Repository
- RSS feed url showing page not found. How to solve it?
- How to convert that page to a wordpress template? [closed]
- Toolbox theme using printif statement – help needed understanding code block
- php file child theme directory not overriding parent theme php file [duplicate]
- How to Create a Multi Purpose Theme?
- Custom Single Page Portfolio Theme [closed]
- What is the point of using the front-page.php template? [closed]