Title: [Plugin: Get the Image] Feature request with code examples
Last modified: August 20, 2016

---

# [Plugin: Get the Image] Feature request with code examples

 *  [Pepe Huerta](https://wordpress.org/support/users/darkpepe/)
 * (@darkpepe)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-get-the-image-feature-request-with-code-examples/)
 * Hi, I’ve been using this plugin since.. I cant remember.. it’s just one of my
   favorites for its simplicity 🙂
 * I want to request a couple of useful features that I manage to pull patching 
   the plugin. Justin, if you dont mind, this are the scenarios and the solutions:
 * **First Scenario.**
 * Open Graph meta tags needs the image url (not the image html code), and get_the_image
   function does not provides a clean url for the image (or at least is not documented).
   So, I added a couple of lines here an there:
 *     ```
       /* Set the default arguments. */
       	$defaults = array(
       		[...]
       		'image_source' => false,
       ```
   
 * Then:
 *     ```
       /* If $link_to_post is set to true, link the image to its post. */
       	if ( $link_to_post )
       		$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) ) . '">' . $html . '</a>';
   
       	if ( $image_source )
       		$html = $image['src'];
       ```
   
 * So, the function will print the image source URL instead of the full html img
   tag:
 * `<?php get_the_image(array('image_source' => true)); ?>`
    Result: [http://example.com/wp-content/uploads/2012/06/example.jpg](http://example.com/wp-content/uploads/2012/06/example.jpg)
 * And now I can use the function for my Open Graph tags:
 * `<meta property="og:image" content="<?php get_the_image(array('image_source' 
   => true)); ?>"/>`
 * **Second Scenario:**
    I need get_the_image to pull the post image linked to it
   self (not to it’s parent post).
 *     ```
       /* Set the default arguments. */
       	$defaults = array(
       		[...]
       		'link_to_image' => false,
       ```
   
 * Then:
 *     ```
       /* If $link_to_post is set to true, link the image to its post. */
       	if ( $link_to_post )
       		$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) ) . '">' . $html . '</a>';
   
       	if ( $link_to_image )
       		$html = '<a href="' . $image['src'] . '" class="attachment-link" title="' . esc_attr( apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) ) . '">' . $html . '</a>';
       ```
   
 * That will return:
    `<a href="http://example.com/wp-content/uploads/2012/06/example.
   jpg" class="attachment-link" title="The Title"><img src="http://example.com/wp-
   content/uploads/2012/06/example.jpg" /></a>`
 * Im sure this can be done in a better way, since I’m a noob at php coding 😛 But
   I humbly submit this to you if you think it proves useful for the plugin!
 * Thank you very much and I really appreciate all the hard work you have put on
   this… you make my life easier! 😀
 * [http://wordpress.org/extend/plugins/get-the-image/](http://wordpress.org/extend/plugins/get-the-image/)

The topic ‘[Plugin: Get the Image] Feature request with code examples’ is closed
to new replies.

 * ![](https://ps.w.org/get-the-image/assets/icon-256x256.png?rev=1735614)
 * [Get the Image](https://wordpress.org/plugins/get-the-image/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/get-the-image/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/get-the-image/)
 * [Active Topics](https://wordpress.org/support/plugin/get-the-image/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/get-the-image/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/get-the-image/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [Pepe Huerta](https://wordpress.org/support/users/darkpepe/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-get-the-image-feature-request-with-code-examples/)
 * Status: not resolved