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
- What’s the difference between home.php and index.php?
- Custom single template for a specific category
- How to insert a logo in the header?
- Page template in two level deep folder
- 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
- 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?
- Add a preview to a WordPress Control Panel
- 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
- Can not Remove Archives and Meta from Sidebar
- Advantages of using instead of wp_enqueue_style()?
- How to add dynamic inline style?
- Enqueued Stylesheets Effecting Admin Styles
- 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]
- Check if password protected post is visible
- 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
- Where can I access my custom page template?
- Theme development question regarding layouts
- 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
- Load child template based on parent
- How can I let templates choose which stylesheets are enqueued?
- create-guten-block in wordpress theme?
- Theme Loading Into Dashboard
- Single page site with history.js
- 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 remove render blocking css from wordpress when you build a theme?
- Move default page templates to sub directory
- What can I use for small text when converting to WordPress?
- Where to place template files?
- Is there any tool to find lines of codes responsible to generate front-end HTML elements?
- How do I get the trackback count of a post in wordpress without writing an SQL query?
- Load sidebar template just once to prevent multiple animations
- Replace single_template filter with what for default posts?
- Need help with adding templates (archives and sitemap) to WordPress child theme
- How to seperate static phrases from template files in custom theme?
- Broken theme, template is missing
- How to add menù section to my WordPress template?
- Having issue with WordPress wp_enqueue_style
- Post and page content not displaying in search results
- Why still output /wp-content/themes/twentynineteen?
- How to add custom meta box when you have a custom page template file
- Password protect a custom template
- Templates dropdown not appearing using _s theme (underscores)
- Load different single.php templates according to post layout selection
- Confused by the behaviour of “front page” / “home” templates
- I need to develop a one-page design
- add jquery file if a certain page is included
- How to link to the page displayed by home.php?
- Under theme folder, what’s sequence of action for index.php, page.php, single.php?
- Is there a template tag I can use to link to the archive page corresponding to the month that a post was published on?
- Adding google fonts to WordPress theme
- Displaying front side empty with one file attached problem
- Find out the reason that the Styles and scripts in the theme are loading properly in localhost but Not in server after deploying
- Template for front page (latest posts)
- which template should I use for single category post?
- 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
- Create a variable with string, array or multiple values
- Using require_once for parent-directory not working but is working in sub-directories
- 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
- What is the point of using the front-page.php template? [closed]
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?
- Theme template file for a specific custom taxonomy