Conceptually wp_add_inline_style
adds some lines as if they were concatenated to a style file. This means that your setup will only work if you are adding the inline style to a style file loaded in the footer, because by the time you are calling add_inline_style
in a template the header has already been assembled.
That said, this is really not a good idea. Functions need to be in the functions.php
file to keep your code readable in the long term. If you want to enable users to add different styles per post, the best approach is to make a custom field for that, which you can read in time to enqueue it in the header.
Related Posts:
- Using wp_add_inline_style without a stylesheet
- How important is it to enqueue a theme’s stylesheet?
- What’s the difference between home.php and index.php?
- Custom single template for a specific category
- Enqueue a stylesheet for login page and make it appear in head element
- How to insert a logo in the header?
- How to move page templates to custom folder?
- Page template in two level deep folder
- Why I can’t add a CSS style in this WordPress theme?
- Is it possible to manipulate the list of page templates?
- The difference between calling wp_enqueue_scripts to load scripts and styles in custom theme
- Different wordpress 404 template for different post type [duplicate]
- How does WordPress decide what template to use as frontpage
- How can I get wp_head() as a string instead of echoing it?
- Adding customizer styles with wp_add_inline_style
- Why does my short code get executed before other content?
- What can I hook into after_setup_theme?
- Retrieve the template directory URI via global or get_template_directory_uri() every time?
- How can I see what template parts are being called for rendering the viewable page?
- Add a preview to a WordPress Control Panel
- Identifying the priority of style.css so I can make a small CSS file load last
- Add a #hash to the links in my custom menu
- Problems with Layout inherit in theme.json
- Adding inline styles from a widget
- The best way to add stylesheets to WordPress
- How to Handle CSS for Multiple Header header.php Files?
- How to load different CSS in different Header?
- Static Front Page problem
- Returning Variables back into a template
- Can not Remove Archives and Meta from Sidebar
- Advantages of using instead of wp_enqueue_style()?
- How to override BuddyPress 3.0 bp-nouveau theme files?
- How to add dynamic inline style?
- Enqueued Stylesheets Effecting Admin Styles
- Setting hero/splash section as a blog post
- Is it possible to use the featured image of a page as a css background without inlining?
- De-registering parent style sheet css recommended?
- Where is the correct place(s) in twentysixteen’s header.php to add a Google webfont?
- How to retrieve an image from a post and display it before excerpt of a post? [duplicate]
- Any tag pagination page (except the 1st page) loads index.php template instead of tag.php
- How do I update WooCommerce template files in my theme? [closed]
- New template, where to place CSS?
- Check if password protected post is visible
- get_query_var() and permalinks
- enqueue_style is not working
- What is the best way to handle multiple calls to get_template_directory_uri() and similar functions?
- Toggle Sidebar Display
- Dequeue a style file which is making website load slow!
- Add theme templates for child categories into the template hierarchy
- Move theme templates to subfolder without losing page associations
- Where can I access my custom page template?
- Theme development question regarding layouts
- Why are theme templates organized as multiple point of entry PHP files instead of reusing your theme’s index.php?
- Is my approach to enqueue styles inefficient?
- Child theme style.css versioning
- WordPress Theme Development: How to redirect templates the right way?
- Disable front-page.php template
- How do I create a custom partial / template?
- Disable wp_enqueue_style for theme on wp-admin
- Change the template of multiple multisite pages at the same time
- functions.php not hooking up with style.css
- Load child template based on parent
- How can I let templates choose which stylesheets are enqueued?
- Stylesheet not linking
- create-guten-block in wordpress theme?
- Override template file i subfolders
- Single Page theme [closed]
- Theme Loading Into Dashboard
- Single page site with history.js
- Do i need to keep all the default WP templates files in a theme?
- How can I detect hierarchal relationships beyond children (grandchild, great-grandchild, etc)?
- How to check if a WordPress core block is active in sidebar
- how to display search term in the template full site editor
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- Font Awesome 5 Free – far working but fas is not? [closed]
- Sort wp_query by sum of two meta fields
- How to override p2 breathe theme plugin in content template file?
- How remove render blocking css from wordpress when you build a theme?
- Should I use template files or just use conditional tags in index.php?
- Different templates for each category level
- Child theme in separate WordPress Install
- How to show children pages as array
- Different stylesheet for different pages not working fully
- Display content on Single page
- Create a variable with string, array or multiple values
- Using require_once for parent-directory not working but is working in sub-directories
- How can I fix the even/odd child classes comments so that the comments are unaffected by the top-level even/odd?
- Problem with multiple menus in theme
- Enable WP to accept standard jQuery code embeding between the tags [duplicate]
- How to output wp_enqueue_style() in HTML head instead of footer
- What is the advantage of using home.php over index.php for the front page
- Enqueue script/style with multiple GET parameters
- Best practice to create required pages
- How customizable is a self-hosted WordPress blog compared to a Blogger blog?
- What is the point of using the front-page.php template? [closed]
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?
- What is the point of using archive.php instead of index.php?
- Theme template file for a specific custom taxonomy
- How to create a template for a post in Query Loop block?
- Twenty Twenty-Four Theme, where to put the personalized CSS style rules?