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?
- Embed dynamic media query in a Gutenberg block
- WordPress Customizer not setting default value upon initial install?
- How to add default images into theme customizer image control?
- Theme Customizer – Dynamic CSS PHP File
- API JSON Data in WordPress
- CSS saved & enqueued, but wordpress doesn’t load css text, only file
- String replace WordPress Site Title
- How do I add JavaScript that will execute on all my sites in Multisite?
- Using PHP in a Stylesheet (possibly a “.htaccess” problem?)
- Use different javascript files for each page on website
- WordPress loop specific thumbnail size
- Is it recommended to pass some data to scripts in `wp_enqueue_scripts`?
- WordPress doesn’t include css
- Using a javascript file to access a get posts array
- Using an Image Slider twice on the same page
- Understanding child theme functions.php
- wp_enqueue_style with style.php and WordPress functions
- Is it possible to use the featured image of a page as a css background without inlining?
- Overriding a theme redux file in child theme
- JavaScript, best way to use data from the loop
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- WordPress Ajax Data problem
- there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
- Remove all nav menu classes ( but keep useful ones… )
- Widgets not showing in my custom theme
- if file_exists not working with wp_enqueue_style
- Javascript code inside “” in core WordPress files .php
- Create custom blocks for bootstrap
- Want to create Child theme, but already edited Parent theme css files and some php files
- Type hinting and void return question
- Run a Parallel PHP Application with WordPress
- How to display custom field on homepage
- Click loads template via ajax
- Customized title tag for each page in pagination?
- Using PHP to toggle stylesheet and header image, set in cookie
- Widget Javascript code (ajax)
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Uncaught TypeError: Cannot read property ‘firstChild’ of null after upgrading to WordPress 5.5
- How to display a value from a radio button in the options menu in wordpress
- Display notification only once
- Add attribute / custom attribute to product in woocommerce
- Access/update database with jQuery
- Use WordPress’s Media Uploader/ Manager in non WordPress php application
- Get/Set wp.customize.previewer.previewUrl
- javaScript in section of WP API
- How should I best target dynamically served content?
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- Different background-image by category
- How to break down importing of feeds
- Style every second widget?
- admin-ajax.php responding with 0
- Using wp_localize_script to store the template url into a variable to use in JS