Or is it because im trying to add it to the css class
.has-post-thumbnail
which is applied to all posts?
Yes, set_featured_background()
gets first post from the loop and add .has-post-thumbnail
to styles. All posts that have thumbnail (with class .has-post-thumbnail
) will have the same background.
Try setting the background in the template file responsible for displaying posts on the home page, probably in content.php
or front-page.php
.
<?php
$attr_style="";
if ( is_home() && has_post_thumbnail() ) {
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
$attr_style=" style="background: url(". $url.'); background-size: 100% 100%;" ';
}
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); echo $attr_style; ?>>
Related Posts:
- WordPress loop specific thumbnail size
- How to scale image with equal width and height without distortion?
- Can I install/embed WordPress on a ‘single page’?
- height should be set to auto to avoid pixelation in the post thumbnail function
- Add a default style if no Featured image is selected
- featured post as div background
- the_author_posts_link css class
- PHP/Manual use of images? – 2 Questions
- wp enqueue style and style sheet depth
- CSS saved & enqueued, but wordpress doesn’t load css text, only file
- How do I get images (with a thumbnail preview) to show in search results?
- Is it possible to use the featured image of a page as a css background without inlining?
- Display All Post Attachments and Assign Class to the Last Image?
- How to display a value from a radio button in the options menu in wordpress
- How to make thumbnail image fit into a div where image dimentions are completely different?
- Assign a picture URL to a page via PHP
- How should I best target dynamically served content?
- is it possible to force wordpress to always save thumbnails as ‘jpg’ not ‘png’
- php syntax – how to concatenate properly – echo bloginfo(‘stylesheet_directory)
- How to Display Image Meta underneath EVERY image in EVERY post
- An unwanted inline style is added to my body tag
- Problem adding class to body_class
- Echo URL of large version of Featured Image
- Get different images for mobile and desktop with php, advanced custom fields without using js and ajax
- Trying to add attribute to my posts’ featured image
- Selectbox in admin panel function linking to CSS
- Using if/else statements with output from theme options
- Is there CSS to expand the gallery limit on Index Pages?
- PHP variable = get_the_post_thumbnail_url outputting without slashes
- How to display pictures from database?
- two columns of posts on homepage, one of them “favorites”
- custom css for admin only
- responsive.css in the WordPress should be prioritized
- WordPress style.css not updating, only after theme reload
- post thumbnail, conditions, else wont work
- Adding logo to WordPress header
- Thumbnails appear to be zoomed
- Odd / Even posts add class minus first post
- Three Questions with Twenty Eleven theme
- WordPress function and string as variable?
- WordPress archive page showing 404 Error [duplicate]
- Styling the second sidebar
- How to add drag and drop functionalities to a div inside option panel
- Removing WordPress Footer -without access to PHP code?
- CSS change in woo commerce Place Order Text [closed]
- Post repeated when opening in overlay, how do I solve this? [closed]
- Split site title and apply different classes
- Else/If Statement to Display Photo Descriptions
- Need help removing […] after excerpt
- jQuery accordion menu
- Twentyfifteen style author comment
- Extend Menu Walker Output
- How to replace URL protocol using PHP?
- Call featured image url
- Dynamic CSS through PHP issue
- How to make changes to style.php [closed]
- Trying to change featured image from 180×180 to full width on home page
- Create Columns with Custom Walker and CSS Classes
- I can’t set image ad fatured programatically
- Background image no longer fits to screen now that project is in php files
- Why would the child theme load in the Customize preview, but not on the site itself?
- How to make only the valid active page of a multilevel menu active with – “.nav li.current-menu-item a”?
- echo cutom css code to WordPress page template file ? is this safe?
- I can’t go to the page archive-{post_type}.php
- Is there anyway I can call the year once?
- I have a background-image in css file but don’t show in site.how to fix this prblm. i sent screenshot. thx
- Trying to generate a CSS file in wordpress uploads folder
- WP Website is shown in HTML
- How to put 2 php codes in functions.php without site crashing
- I cannot find the wordpress.scss file that my live site is pulling from
- I have a lot of JavaScript erorrs after SSL someone can help me?
- I got big white screen when i attach main style sheet of Html in functions.php
- register dependency css and js inside a plugin class
- WordPress generate images size after upload
- Having trouble with customizing blog posts on the home page
- Styling a specific post after hovering over it
- CSS loading as empty file in Custom Theme
- user update profile for custom code
- get_post_thumbnail_id returns a negative number
- How limit the width of a fixed menu-bar on scroll?
- Where to find the html for WordPress site? [closed]
- Basic PHP question (displaying post title over thumbnail) [closed]
- How to remove image on single product and get product to span page?
- insert thumbnail image from php script
- widget: input the px value from user and use it as inline style in widget function
- Echo the featured image of page assigned to blog in index.php
- Show contact 7 form in popup
- How Can I Center the Logo in the Navigation Menu? [closed]
- How to change the menu color
- Setting post thumbnail sizes in template file and functions.php
- How to get shared CSS body class between translated WPML pages [closed]
- How to customize posts in WordPress by using HTML and CSS?
- How to create and add js and css file when server is not on my PC?
- which php or css file has generated an inline style in WordPress that overwrites my css
- Header location [closed]
- Blog listing not showing dates for every post and arrow missing off image
- Blog Posts not sorted and pagination not adjusted after filtering some category
- Remove default Image Sizes
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)
- ‘This Field is Required.’ is Not Displaying on CF7 [closed]