The correct method is to enqueue the stylesheets, via callback hooked into wp_enqueue_scripts
. You can add the contextual conditionals inside the callback:
function wpse124258_enqueue_scripts() {
if ( ! is_admin() ) {
// Conditionally enqueue
if ( is_front_page() ) {
// Front page stylesheet
wp_enqueue_style( 'front-page-style', get_template_directory_uri() . '/front-page-stylesheet.css' );
} else if ( is_page() ) {
// Static page style
wp_enqueue_style( 'static-page-style', get_template_directory_uri() . '/front-page-stylesheet.css' );
} else {
// Default style
wp_enqueue_style( 'default-style', get_stylesheet_uri() );
}
}
}
add_action( 'wp_enqueue_scripts', 'wpse124258_enqueue_scripts' );
For more information, refer to the Codex for wp_enqueue_style()
.
Related Posts:
- How to get the registered sidebar’s name by its id?
- Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
- One button to change all settings in theme customizer?
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- Design view breaking on Pages
- Can’t load WP function into external function
- Set WordPress Default Template
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- How do I link a button I created in theme customizer to a function?
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- get_template_directory adding FTP root folders in urls
- How to make sure relative URL works when site is not on root domain?
- Dynamically switch file in get_template_directory_uri() | Function [closed]
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- Menu to the right of screen on desktop using Bootstrap 4
- Proper use of Output Buffer
- List of all theme customizer control types?
- Is having multiple theme customizers for different pages possible?
- function_exists call in function.php
- Debugging an error: wp_enqueue_style was called incorrectly
- reason of splitting theme files to multiple files
- Dynamically change feature image in customiser
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- Understanding WordPress child theme custom JS loading
- How can I loop into two different DIVS without repeating the DIVs
- Removing unnecessary wordpress files
- Remove css styles from specific page
- Use different javascript files for each page on website
- Is the regular ajax request method safe or I should use admin-ajax.php?
- How to get custom image size for image uploaded in Customizer
- Widgets not showing in my custom theme
- Can I change a variable in a content part while calling it?
- How the functions in WP are called in tags
- What is the fastest way to load PHP functions that are only used in one theme template?
- My Own layout in WooCommerce pages [closed]
- Differences when using the the_time and the_date functions
- Add a Second Menu to a theme that only support 1 menu
- Changing the template hierarchy
- Customizer: Output default value in Customizer CSS
- WordPress does not load page.php, return 404.php
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Where in PHP do I move title and meta (date) to bottom of each blog section?
- Converting HTML Template to WordPress Theme
- WordPress add post format support not working
- How to remove the cufon script from Dzonia Lite theme [closed]
- How do I add custom bulk actions to multiple custom post types?
- adding custom user input fields in WordPress admin dashboard gives error The link you followed has expired. Please try again
- Error in custom php function doesn’t exist
- Populate editor with some content of a page with a page template
- Skt full width basic slideshow problem
- How to disable controls in theme customizer?
- WordPress admin-ajax.php
- What does this mean in wordpress? Easy question
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Why am I getting a different filename? And how does WordPress load singular.php for both Page & Post? (Fresh WordPress installation)
- Reason to add a name of the theme like (‘menu-1’ => __( ‘Primary’, ‘twentynineteen’ ),) in PHP?
- Separation of presentation and code – WordPress
- How to call multiple functions from multiple files into a WordPress page template [closed]
- What is the best way to define constant options for a theme?
- Save Custom CSS file in the upload folder dynamically?
- Warning: printf(): Too few arguments in helpers.php file
- home.php show blog posts as grid view
- How to Update an old theme for the latest wordpress version
- get_comments_number() returns 0
- Removing “Powered by” footer using child theme PHP [closed]
- get_page_templates only return templates with “home” in the filename
- Is there a hack for using is_page() within the function.php file?
- Extract and display user infromation on an automatically created page
- Show different website layout if no sidebar added
- Need advice on theme customizer and child themes
- Some problems calling a function into sprintf() inside functions.php template file [closed]
- Commas in Tag Cloud
- Need help for some PHP code
- How to change basename url for wp-admin?
- how to replace h1 entry title with h2 in category pages only
- Not able to remove caption shortcode from the content
- remove_action from parent theme using child theme functions.php
- require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
- Display post date also if the date it’s the same for each post
- How to override theme’s public static function inside of a trait?
- how to use 2 index.php file One for mobile and one for desktop
- Theme editing “post thumbnail” help
- How to add Open/Close Toggle button into Twenty Fifteen theme for hiding left sidebar?
- Use Custiomizer to setup meta theme color tag
- Rotating Header Images
- Where can I find the declaration of `$_wp_theme_features`?
- Calling PHP function doesn’t work in index.php
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- Save the outputted image into the Media Library, with a different filename and extension
- WordPress get_post_meta issue
- WP Knowledge Base Theme bug – Subcategories and Articles, Need to change WP_Query
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- How to add button to top of theme customizer?
- Adding code to the function file
- I need a button to appear when not loged in and another when logged in, I need help fixing code PLEASE!
- Load slideshow.css file only if Slideshow is checked / on
- Predefine Magazine Style Layouts
- How to store the_post_thumbnail() value in a variable
- a problem in class in class-wp-hook.php