The easiest way I’ve seen is to echo
it where you need it:
function inline_css() {
echo "<style>html{background-color:#001337}</style>";
}
add_action( 'wp_head', 'inline_css', 0 );
Since 2019 you can also add styles inline inside the body
, shown here without using echo
:
function example_body_open () { ?>
<style>
html {
background-color: #B4D455;
}
</style>
<?php }
add_action( 'wp_body_open', 'example_body_open' );
The benefit here is you get better syntax highlighting and do not need to escape double-quotes. Note this particular hook will only work with themes implementing wp_body_open
hook.
Related Posts:
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- How to load scripts/styles specific for a page
- How do I create a new WP admin color scheme?
- Add attribute to link tag that’s generated through wp_register_style?
- TinyMCE custom stylesheets for different post types
- Remove “says” from comments
- Is it possible to be more page/post specific with admin_enqueue_script?
- Child Theme Not Overriding Parent Theme
- CSS stylesheet not loading
- Enqueue styles after a plugin
- How to use max and min values of custom fields
- Add class or ID to any WordPress function
- Register and enqueue style.css custom theme
- Multiple CSS body classes to specific page I.D.’s – is this possible?
- Why does the ‘wp_nav_menu’ function work only until a menu is created?
- Retrieve tags data in post body
- Having issues with a foreach inside of a shortcode with ACF gallery
- Child Theme files – what is needed?
- How do I add Bootstrap and LESS to my migrated WordPress site?
- How to Display Frontend CSS for Administrator only
- WordPress Menuing Question :focus
- Get Current Post ID in functions php, meta query filter
- Change CSS for logged in users
- Redirect to another page using contact form 7? [closed]
- How to stop wordpress from injecting hard-coded style into image attachments with captions
- different style sheet for just one page template
- How to retrieve the values of a sub-field in the first and last row of an (ACF) repeater inside function?
- Is my code correct to enqueue CSS on a specific page?
- header_image() with CSS
- Not all CSS elements transferring via parent to child?
- Split Media Queries in different files!
- Some questions about how proper add 2 CSS file in a WordPress theme?
- problem loading stylesheets to wp_head dynamically
- Add php code to wp_print_scripts?
- Can set_post_thumbnail be used to remove a thumbnail?
- Programmatically add Yoast meta description after post save
- Parent theme styles overriding child theme CSS [closed]
- Theme JS is available but theme CSS isn’t
- Proper Way to Load stylesheet on Condition
- Default Nav Highlight
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- Custom styles in Tiny MCE with an external CSS file
- why can’t i add front.css to my frontpage.php
- get_template_directory_uri() links to child theme not parent
- Using two loops in one WordPress template
- Getting out side of wp root folder from function.php using absolute path
- Insert a field with PREG_REPLACE – strange behaviour
- Page Template Won’t Load Correct CSS File
- current_page_item is missing inside wp_nav_menu
- Perform function on publish AND save (not just save)
- define css class in functions.php
- Display ACF category image on archive and single template files
- Featured Image and Tags problem
- Completely Disable WordPress RSS Feeds
- Override a Post’s URL with Advanced Custom Fields Function
- WordPress Function Assistance with Loop
- How to show ACF value under post/page title in wp-admin
- How to display an image before title text in menu items
- Advanced method to control cache of enqueued style/script
- Filter works on last selection but no others
- Combine page types and Custom Taxonomy in a functions.php command
- Can’t load assets
- How to update an image attachment’s alt text from a custom field when saving a post?
- CSS style and app.js not loading
- Help with with my function for wordpress
- Stylesheet does not load despite functions.php
- Remove clickable Link of WordPress Site Logo from Woocommerce Single Product page
- How do I make a custom “Read More Blogs” button for my blog page
- Help using ShortCodes to style whole chunks of the post
- ACF Date Form in Custom Admin Field
- Assign IDs to headings in ACF using functions.php
- Setting Up Child Theme To Take Priority
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- CSS disabled after getting rid of emoji
- How to add styles in existing function?
- get_field() with ID in one signal filter not working
- Woocommerce – Switching Price for Category
- Echo a String Based On Geolocation? [Woocommerce || ACF]
- How do I dequeue a Stylesheet, stored in an ‘Assets’ folder?
- Comment function for page
- Child Theme not loading multiple stylesheets
- Correct way of Enqueue self hosted fonts in sass project
- Help with is_page() and calling css for specific pages in a Child Theme
- Child theme style.css didn’t work properly but the Customize Additional CSS did [closed]
- Return ACF Field value function
- Providing fallback function and allow override by plugin
- Different body image backgrounds on different pages, posts and categories
- update_post_meta not working in function
- Changing the color of post title [closed]
- Preventing PHP Execution in Parent Theme
- Functions.php in child theme that loads CSS file breaks website
- Syling Custom Fields echo’s from from functions.php
- does acf_save_post cause endless loop?
- Should I use `get_stylesheet_uri()` or `get_template_directory_uri()` when calling my CSS Stylesheet?
- How can I append and prepend something to all post hyperlinks without using ::before or ::after? PHP hook solution?
- Call ACF data from functions.php [closed]
- Image width issue in IE [closed]
- How do I make my child theme’s CSS update when I save it?
- Why don’t ‘wp_nav_menu’ CSS classes work until a menu is created?
- wp_head not injecting css