In most themes anything added via the wp_head
hook should appear after (and override) enqueued CSS.
So you could add an action to the themes functions.php and use get_queried_object_id()
for the post ID.
function my_dynamic_css() {
$custombg = get_post_meta( get_queried_object_id(), 'custombg', true );
if (! empty($custombg)) {
?><style>#Box2 {background: <?php echo $custombg; ?> }</style>
<?php
}
}
add_action( 'wp_head', 'my_dynamic_css');
Presumably, rather than having the rest of your CSS in a PHP file you could enqueue it as a standard CSS file. If not you could “include” it by adding <link rel="stylesheet" href="https://wordpress.stackexchange.com/pathto/my/style1.css" />
to the above function or use heredoc.
Related Posts:
- WordPress Admin Bar pushed Sticky Footer off the bottom of the page
- Add a class to links in the visual editor (how to get old dialog back)
- How to remove hardcoded characters from playlists?
- How to preserve PHP modifications while upgrading WordPress?
- Limit the Excerpt field in WP-Admin in words
- Minify HTML, CSS, JS with PHPWee?
- Archive dropdown styling not applied
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Displaying theme options in css
- Show post in slider
- Slider loading issue
- Selectbox in admin panel function linking to CSS
- Can I install/embed WordPress on a ‘single page’?
- Customize Theme comment template to Insert VoteUp and VoteDown buttons
- Incorrect MIME type for assets with Valet
- How to add a do_action on refreshing of WP customizer?
- Customize position of social icons in upme plugin [closed]
- Menu jumping when calling it via PHP
- How does wp_enqueue_scripts work?
- Media Upload , file name changed automatically
- How do I add a custom css to all posts without affecting homepage css? [closed]
- Redirect to another page using contact form 7? [closed]
- Custom Background by Page IDs
- Add Codepen animation as Preloader to WordPress
- Clickable image link sends people to wrong URL
- trouble with page_id & highlighting current page
- wordpress admin plugin menu custom css
- How to add drag and drop functionalities to a div inside option panel
- How to Change CSS Colors from Custom Plugin Settings Page
- Post repeated when opening in overlay, how do I solve this? [closed]
- Link to page with posts of specific type
- Assign Custom classes to every Excerpt
- How to sort posts by active category in WordPress?
- Create Columns with Custom Walker and CSS Classes
- Add other class content with reference class value
- How do I integrate vanilla Javascript to a wordpress website?
- Google CSE Malfunctions via Chrome/Safari on Mobile When Clicking on Either Search Icon/Menu Icon. How to Make Google CSE Default Theme Search
- I have a lot of JavaScript erorrs after SSL someone can help me?
- WordPress Slider is not working
- register dependency css and js inside a plugin class
- Bring Font Awesome icons inside menu A tags
- Automatically refresh page if widget is added to page?
- Target a specific container to style on WordPress storefront theme
- Where to find the html for WordPress site? [closed]
- Why isn’t my custom Javascript showing up in my custom template?
- Trying to customize wordpress drop down categories
- How to create and add js and css file when server is not on my PC?
- hello can you advise how to fix the error?
- Adding first / last CSS classes to menus
- WordPress Visual Editor Stripping HTML Changes
- Infinite-Scroll Plugin and Jetpack Infinite Scroll Plugin – Adding to “Thoughts” Theme
- Handling an Ajax form submit
- Is it recommended to pass some data to scripts in `wp_enqueue_scripts`?
- Using an Image Slider twice on the same page
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- if file_exists not working with wp_enqueue_style
- Using PHP to toggle stylesheet and header image, set in cookie
- How to speed up admin-ajax.php in wordpress
- JQuery not working on WordPress Admin page [closed]
- Putting PHP variables into javascript [duplicate]
- How does this WordPress Plugin (Thrive Comments) apply their custom comment sort? [closed]
- Change the site tagline (or similar) based on current page
- How to style options page in dashboard?
- Theme Options Page – User Updates Logo
- Status 400 for AJAX POST Request with admin-ajax.php
- Generate sidebar depending on height of post
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- What exactly do this function declared into functions.php file of a WP theme?
- WordPress wp_add_inline_style unable to give hex colors?
- How to create table in wordpress without plugin? [closed]
- Ajax search shows all results when user empties input?
- Why i can’t get custom fields value or post ID via Ajax?
- List post by title length
- How to reference PHP in Javascript
- get db values for external js file
- Ajaxurl suddenly not defined
- WP insert post Redirect after function has executed
- html form: redirect page after form completes submit function and posts data
- Creating a brand attribute as a variable
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- Featured image in menu wordpres
- Adding Custom css file in the wp-uploads directory with custom php functions
- Cannot dequeue Elementor Font Awesome css
- How to find and delete a menu item in php?
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- How to display post meta bellow every posts
- Pulling Products from an API
- Redirect after login depending on the URL
- How to call a function from functions.php with ajax?
- Full search and replace isn’t enough to make all pictures to be loaded with https
- How to add Open/Close Toggle button into Twenty Fifteen theme for hiding left sidebar?
- Find the method which AJAX GET calls
- Retrieve $_POST data to send to javascript without using localize script
- How to call javascript function (jquery) in a shortcode?
- Revision History for Entire WordPress Site
- Widget header unique classes
- why is this content-template not showing any of my blog-entries?
- How to get the count for each taxonomy term
- How to add margin underneath woocommerce total price amount -> productpages
- how can I make content from a plugin hidden when user is logged in? [duplicate]