PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 30, 2022

[FIXED] Wordpress featured image outside of loop

 January 30, 2022     wordpress     No comments   

Issue

I want to display the featured image outside of the WP-loop. e. g. like a background image of the body that is different in every post. I looked for two hours on google, but could not find a single piece of code that gives me an idea. But I suppose it is not that much complicated.

Has anybody here an idea how the retrieve the URL of the featured image outside the loop?

thank"


Solution

Here's my preferred way:

<?php
$page = get_page_by_title('Title Here'); 
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'full' );
?>

<div class="background" style="background-image:url('<?php echo $image[0]; ?>');"/>


Answered By - androidoverlord
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing