Title: Function to get post image URL?
Last modified: November 16, 2020

---

# Function to get post image URL?

 *  Resolved [oguruma](https://wordpress.org/support/users/oguruma/)
 * (@oguruma)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/function-to-get-post-image-url/)
 * I am trying to make a single template, and I want to make a jumbotron/header 
   area that uses the post image as a background.
 * What function do I use to pull in the post image URL (falling back to the category
   image if there are no images uploaded for that post)?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [1naveengiri](https://wordpress.org/support/users/1naveengiri/)
 * (@1naveengiri)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/function-to-get-post-image-url/#post-13677690)
 * Hello
 * there is a function for loading images of GD with a fallback option.
 * `geodir_get_images($post_id, $options['limit'], $options['show_logo'],$revision_id,
   $options['types'],$options['fallback_types']);`
 * [https://github.com/AyeCode/geodirectory/blob/master/includes/image-functions.php#L234](https://github.com/AyeCode/geodirectory/blob/master/includes/image-functions.php#L234)
 * but you also have other options where you can use post_image shortcode.
 * `example: echo do_shortcode('[gd_post_images title='' types='' fallback_types
   ='cat_default' ajax_load='true' limit='1' limit_show='0' css_class='' type='image'
   slideshow='true' controlnav='1' animation='slide' show_title='false' show_caption
   ='false' image_size='' aspect='' cover='' link_to='' link_screenshot_to='' bg
   ='' mt='' mr='' mb='' ml='' pt='' pr='' pb='' pl='' border='' rounded='' rounded_size
   ='' shadow='' ]');`
 * I hope it will be helpful.
 * Regards
 *  Thread Starter [oguruma](https://wordpress.org/support/users/oguruma/)
 * (@oguruma)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/function-to-get-post-image-url/#post-13679506)
 * Thanks for getting back to me!
 * I don’t think that will work, since I need the URL to set a background, and your
   code will echo an image in  tags
 * For example:
 *     ```
       <div class="mygeodirectoryarea">
        <h1> The Post Title </h1>
       </div>
       ```
   
 * I want to use the post image URL to set a background, for example:
    `.mygeodirectoryarea{
   background-image: url("PUT THE BACKGROUND IMAGE URL HERE")}`
 * So, I need the image _URL_, not the image in  tags.
 *  [1naveengiri](https://wordpress.org/support/users/1naveengiri/)
 * (@1naveengiri)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/function-to-get-post-image-url/#post-13680711)
 * Hello,
 * Try this function
 *     ```
       function custom_get_post_image_url( $post_id='' ){
       	$post_id = !empty( $post_id )? $post_id: get_the_ID();
           $featured_img_url = get_the_post_thumbnail_url($post_id, 'full'); 
       	$term_img = '';
       	if ( empty( $featured_img_url ) ) {
               $default_term_id = geodir_get_post_meta( $post_id, 'default_category', true );
               if ( $default_term_id ) {
                   $term_img = get_term_meta( $default_term_id, 'ct_cat_default_img', true );
               }
           }
           if ( ! empty( $term_img ) ) {
       		$default_img_id = ( !empty( $term_img['id'] ))? $term_img['id']: 0;
       		$featured_img_url = wp_get_attachment_url( $default_img_id );
       	}
   
       	return $featured_img_url;
       }
       ```
   
 * Regards

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Function to get post image URL?’ is closed to new replies.

 * ![](https://ps.w.org/geodirectory/assets/icon-256x256.jpg?rev=2778361)
 * [GeoDirectory - WP Business Directory Plugin and Classified Listings Directory](https://wordpress.org/plugins/geodirectory/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/geodirectory/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/geodirectory/)
 * [Active Topics](https://wordpress.org/support/plugin/geodirectory/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/geodirectory/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/geodirectory/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [1naveengiri](https://wordpress.org/support/users/1naveengiri/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/function-to-get-post-image-url/#post-13680711)
 * Status: resolved