This is what you could do:
1 – Put the CSS in a separate file and save it in your theme directory.
2 – Add the following code in your functions php
:
function wpse_89494_enqueue_scripts() {
if ( has_nav_menu( 'secondary' ) ) {
wp_enqueue_style(
'wpse_89494_style_1',
get_template_directory_uri() . '/your-style_1.css'
);
}
if ( has_nav_menu( 'primary' ) ) {
wp_enqueue_style(
'wpse_89494_style_2',
get_template_directory_uri() . '/your-style_2.css'
);
}
if ( ! has_nav_menu( 'primary' ) && ! has_nav_menu( 'secondary' ) ) {
wp_enqueue_style(
'wpse_89494_style_3',
get_template_directory_uri() . '/your-style_3.css'
);
}
}
add_action( 'wp_enqueue_scripts', 'wpse_89494_enqueue_scripts' );
Related Posts:
- Why wp_register_style() is important while I’m using a complete wp_enqueue_style()? [duplicate]
- How to add crossorigin and integrity to wp_register_style? (Font Awesome 5)
- How does one load style.css into a theme?
- Loading a child-theme’s style.css after the parent’s
- Add ‘title’ attribute to stylesheets with wp_enqueue_style()
- wp_enqueue_style for Plugin with multiple stylesheets
- How to add extra attribute to stylesheet link?
- Why my CSS file is not being registered in functions.php? [closed]
- How Would You Enqueue A Google Web Font?
- Does wordpress wp_enqueue_style support noscript?
- Enqueue a css using negative conditional tags
- Duplicated CSS files using wp_enqueue_style()
- Remove inline css added by wp_add_inline_css
- Enqueue styles through the wp_enqueue_style function vs link tag inside header.php
- Stylesheet from wp_enqueue_style is overwritten by plugin
- How to force stylesheet to load before anything else in header?
- Add Font Awesome Embed CDN Script To WordPress
- wp_add_inline_style in plugin not working
- My child theme CSS get called twice
- To enqueue or not to enqueue
- Enqueue stylesheet depending on template
- Google fonts enqueue only imports last font family
- I register and enqueue stylesheet but nothing is rendered
- Enqueued Stylesheet Version Number Not Being Appended
- I want to include my style.css in function.php file?
- How to dequeue wp_get_custom_css in Twenty Twenty Theme
- Can’t make wp_enqueue work
- Combining multiple stylesheets into one conditional block
- How to link style.css in functions.php
- My style in my child theme loads after the parent theme, but it breaks stuff: How do I load it before the parent theme?
- How to enqueue stylesheets?
- Best way to enqueue CSS and JS in a specific location
- Enqueue stylesheets with the same name
- wp_enqueue_style will not let me enforce screen only
- Never Enqueued Stylehsheet
- Changes in enqueued / registered stylesheet paths not updating—why?
- How to dequeue theme’s RTL stylesheet?
- How can I add style sheet link to my wordpress page
- Which is the best way to incorporate custom fonts?
- Stylesheet not loaded on register page
- Loading custom CSS
- wp_enqueue_style not working if the file is in a sub folder
- Custom style sheet won’t enqueue / load if the css file actually exists. [closed]
- Additional CSS – crashing with javascript-html minifier?
- How do I view registered syles and scripts for enqueue
- wp_enqueue_style in WordPress plugin class not working
- stylesheet in header or functions?
- enqueue_parent_style
- Add wp_add_inline_style into another wp_add_inline_style for better performance
- 404 Not Found on CSS file even though it’s in the correct directory
- What is the difference between the different ways of linking stylesheets
- CSS only loads in backend
- Enqueuing a stylesheet and ensuring it’s loaded before (not after) the theme’s stylesheet
- Proper use of wp_enqeue_style
- What is the colors handle from WordPress core for and why does it not have a path?
- make admin.css in my child theme
- Custom WordPress Theme loads js but not stylesheets
- Why is my wp_enqueue_style() not working?
- Google Fonts not loading correctly
- Un-enqueue styles for certain built-in Gutenberg block types?
- Enqueueing styles with version variable
- Enqueue style for specific site type
- How to properly add my styles overriding current styles
- Can’t get custom CSS file to load in Child theme
- Missing dns-prefetch link when using “nested” wp_register_style
- Is there a way to deque the style with higher priority?
- Why wp_enqueue_style() is adding CSS class?
- Why isn’t my plugin script loaded in the backend?
- How to get rid off default css styles
- Deregister a CSS file that comes with a plugin
- How To Load wp_add_inline_styles
- style.css is not loaded in other template files than index.php (eg. front-page.php)
- Enqueued style gets commented if not logged in
- Move dashicons.min.css to Footer
- Can’t Workout Dependency of Stylesheets
- Homepage not loading correctly, but then loads when refreshing
- Edit CSS of a plugin
- How can I troubleshoot enqueue in general and loading Google fonts specifically?
- How to offload CSS and JS files from wp-content/themes folder?
- Stuck with Enqueue Styles for multiple css files in a child theme
- Customize the reset password page?
- font style is not working on domain
- wp_enqueue_script stopped working
- Enqueue custom jQuery UI theme to override Google CDN theme
- Different styles on multiple pages
- Unable to load stylesheet via wp_enqueue_style
- wp_enqueue_style url is trimmed somehow
- Custom admin bar css on front end bug
- Stooping a css file from loading in the header
- Trying to get styles to register than enque
- enqueue style sheet and bootstrap
- Why is wp_enqueue_style not working?
- Stylesheet version not showing in browser when adding version number to stylesheet in enqueue
- How do I remove Google Fonts from a parent theme?
- .editor-styles-wrapper overriding my block styles in Gutenberg
- If is multiple page templates
- Loading different stylesheet on WordPress pages?
- How can I properly enqueue tags in WordPress to use with Web Components?
- child parent styles enqueue order
- How to check widget-cpt meta and display its custom css in the head?