• Resolved mrspabs

    (@mrspabs)


    I am using this code to use my thumbnail as a background of a div. can someone help me write this so that if there is no thumbnail, to serve an static image?

    <div style=”background: url(<?php the_post_thumbnail_url(‘custom’); ?> ); background-size:cover; background-position:cover;”>

Viewing 1 replies (of 1 total)
  • Thread Starter mrspabs

    (@mrspabs)

    Figured it out

    <div style=”background: url(<?php
    if ( ” != get_the_post_thumbnail() ) {
    the_post_thumbnail_url(‘custom’);
    }
    else {
    echo get_bloginfo( ‘stylesheet_directory’ ) . ‘/img/blog-placeholder.jpg’;
    }
    ?> ); background-size:cover; background-position:cover;”>

Viewing 1 replies (of 1 total)

The topic ‘thumbnail as background image with fallback’ is closed to new replies.