WPITECHWPITECH

    Subscribe to Updates

    Get Latest WordPress Tutorials and Updates

    What's Hot

    12 Best Ecommerce Software in 2021 & in the Future

    July 31, 2021

    Why Is My Canon Printer Not Printing Properly?

    July 31, 2021

    5 Best Google Analytics Plugins

    May 28, 2021
    Facebook Twitter Instagram
    Facebook Twitter Instagram
    WPITECH WPITECH
    Subscribe
    • Home
    • Tutorials
      • WordPress Tutorials
      • WordPress Plugin
      • WordPress Themes
      • WooCommerce
      • Ecommerce
      • PHP
    • Hosting
    • Deals
      • Hosting Deals
    • SEO TOOLS
      • Bulk Url Checker
      • Structured Data
      • Google Cache
      • Hyperlink Generator
      • Free URL Checker
    • Marketing
      • SEO
      • Advertising
    • Reviews
    • Write for Us
    • About Us
    WPITECHWPITECH
    Home » How to Get WordPress Post Featured Image URL & Post Thumbnail
    WordPress Tutorials

    How to Get WordPress Post Featured Image URL & Post Thumbnail

    WPITECHBy WPITECHJuly 10, 2019No Comments1 Min Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Featured-Image-URL-WordPress
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Nowadays developer needs the direct URL of featured image and it is mostly possible when the featured image is used as a header or the post background image.

    Place the following code snippet in the files including single.php, post.php, and template.php to get the URL:

    <?php
    $blog_fetrdimg = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    ?>
    <div class="blog-featured-image"
    <?php if( $blog_fetrdimg ) : ?>
    style="blog-featured-background-image: url(<?php echo $blog_fetrdimg; ?>);"
    <?php endif; ?>
    >
    </div>

    Use the following CSS snippet to style the featured image:

    . blog-featured-image {
    background-position: 50% 50%;
    background-repeat: no-repeat;
    background-size: cover;
    width: 100%;
    }

    Get Single Post Thumbnail

    For enabling the support for the featured image in post and pages use the following snippet code. The snippet will be enabled in single.php

    <?php if (has_post_thumbnail( $post->ID ) ): ?>
    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    <div id="custom-bg" style=" blog-featured-image: url('<?php echo $image[0]; ?>')">
    
    </div>
    <?php endif; ?>

     

    Get WordPress Post Featured Image URL Post Thumbnail
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    WPITECH

    Related Posts

    9 Amazing Benefits of Using WordPress for Your Projects

    May 15, 2021

    Must have Features for WordPress Website

    February 4, 2020

    WordPress vs Squarespace: Best Comparison 2020

    January 6, 2020
    Add A Comment

    Leave A Reply Cancel Reply

    Recent Posts
    • 12 Best Ecommerce Software in 2021 & in the Future
    • Why Is My Canon Printer Not Printing Properly?
    • 5 Best Google Analytics Plugins
    • 12 Best Email List Building Tools in 2021
    • 9 Amazing Benefits of Using WordPress for Your Projects
    Recent Comments
    • 20+ Top Ecommerce Marketing Agencies To Hire for 2020 on Conversion Rate Optimization Tips to Improve Conversions and Increase Revenue
    • Hottest B2B Content Marketing Trends and Statistics in 2019 on The Ultimate Guide to Broken Link Building 2020
    • Digital Chetan on SEO 2020 Google RankBrain Algorithm GUIDE
    Editors Picks
    Top Reviews
    Advertisement
    Demo
    Facebook Twitter Instagram Pinterest Vimeo YouTube
    • Home
    © 2022 All rights reserved

    Type above and press Enter to search. Press Esc to cancel.