PHP code cannot run in .css
file, however you can use inline style, such as:
<div style="background-image: url("<?php //url ?>");">
or
<style> .class-name { background-image: url("<?php //url ?>"); } </style>
The above would be useful when working with custom fields for dynamic image paths.
If the image is located in the theme directory, PHP won’t be needed, let’s say the image folder is directly under the theme folder /theme-name/images
, and the stylesheet is /theme-name/style.css
, then you can just add the background image to the css file as follows:
.class-name { background-image: url("images/file.jpg") }
Related Posts:
- Child theme css not overriding parent
- wordpress menu dropdown item not showing after first dropdown
- WordPress get_template_directory_uri() not returning https and only return http
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- xajax expanding list query
- How can I find my php.ini on wordpress?
- $wpdb->update or $wpdb->insert results in slashes being added in front of quotes
- Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes)
- WordPress Error : Upload folder is not writable. Export and file upload features will not be functional
- WordPress child theme style.css not working
- Prioritize Visible Content WordPress
- Get user role by ID WordPress
- do_shortcode not working
- WooCommerce action hooks and overriding templates
- Contact Form 7 – Custom Validation
- XAMPP, using port:81, cannot run localhost:81/mywebsite
- WordPress query single post by slug
- How to integrate WordPress with Angular 8 for website?
- Create a folder if it doesn’t already exist
- How to remove index.php from WordPress site URL
- WordPress visual composer not loading
- Redirect after Login on WordPress
- WordPress: How to overlay text / widget div on top of a revolution slider
- WordPress Email Share button not opening in Outlook
- how to create a custom live search in WordPress from scratch
- Local wordpress install only shows home page, all other pages Not Found
- WordPress Bootstrap Handburger Menu Wont Open
- Divi Child Theme Breaks WordPress Customizer
- WordPress Salient theme: getting a full width 2 columns portfolio
- WordPress- url for localhost wp-admin is not working
- WordPress- url for localhost wp-admin is not working
- Muffin Builder has a limit? (WordPress – Be Theme)
- Adding style.css in wordpress, the correct way
- How to correctly use get_template_directory_uri() WordPress function to load an image that is in a subfolder of my theme?
- Correct way of using wp_get_attachment_image() in wordpress
- How to fix “Headers already sent” error in PHP
- http://localhost:80 is not working on running Apache server through UniServer ZeroXIII
- How do I get PHP errors to display?
- Get the full URL in PHP
- How to force file download with PHP
- How to Set Category Page as Home Page in Prestashop
- What are the differences in die() and exit() in PHP?
- Expected status code 200 but received 500
- Get Current URL in Magento and show something
- How to call function of one php file from another php file and pass parameters to it?
- SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
- Convert php array to Javascript
- phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user ‘pma’@’localhost’ (using password: NO)
- SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens on line 102
- ERROR: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it
- What does double question mark (??) operator mean in PHP
- How can I find the php.ini file used by the command line?
- Check if a PHP cookie exists and if not set its value
- Deprecated: mysql_query() [duplicate]
- Call to undefined function mysql_query() with Login [duplicate]
- PHP Error : Fatal error: Constant expression contains invalid operations
- JavaScript equivalent of PHP’s in_array()
- Implement linked list in php
- Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
- PHP: date function to get month of the current date
- How to make PDF file downloadable in HTML link?
- Redirect old php link to wordpress link in .htaccess
- What is the meaning of ‘OFFSET’ => 1 (WordPress)
- WordPress custom thumbnail size
- Random Question Mark Icons In WordPress Text
- How do i download code files of the website from wordpress.com?
- What does arg mean in WordPress
- WordPress dFactory Cookie Notice Plugin
- How to use wp_enqueue_style() in my WordPress theme?
- About 404 during WordPress installation
- “The Events Calendar” plugin by Modern Tribe in WordPress not working
- WordPress Main Menu – Hide ‘Home’ link on homepage only
- Scalable wordpress setup
- WordPress – Display Random Number Between 190-250
- Set size of WordPress thumbnail post
- In wordpress how can I scrape and show social media data of users like in upfluence.com and shoutcart.com?
- How to change “Leave a Reply” title in wordpress twentyfifteen theme
- I have shifted my wordpress site from one host to another, after shift the website wp-admin is not open
- How to use wp_mail() function in wordpress
- Custom Coupon type woocommerce wordpress
- functions.php not adding css to website?
- How Display Posts on category
- Parent theme CSS overriding child CSS rules
- Dynamic Stylesheet loads but doesn’t finish
- How to add date to navigation bar
- Incorrect MIME type for assets with Valet
- trouble with page_id & highlighting current page
- Timber right sidebar in WordPress theme
- How to Remove Theme Style CSS inside Custom Plugin?
- 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?
- WordPress Slider is not working
- Add Shortcode to ::before class
- Custom Thumbnails [closed]
- Display pages from specific page template
- Sidebar doesnt get updated?
- Add a “Next Post” & “Previous Post” styled button manually to a post
- inner-wrap div pushing custom table far down on page
- Option value not getting updated until page refresh in WordPress