RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.38% (6.14%*) • Home Loan Fixed: 5.44% (6.26%*) • Fixed: 5.44% (6.26%*) • Variable: 5.38% (6.14%*) • Investment IO: 5.69% (6.52%*) • Investment PI: 5.49% (5.98%*)

Demo Code to Import Remote Image Into WordPress

The following snippet supports the article on this page titled "Import Remote Images into WordPress and Return Image URL, Image ID, and Image Dimensions". It will import a remote image into the WordPress media library, create all the relevant image sizes, and return the local image link or array of image data.

1
<?php 
2
/*
3
 Code to demonstrate the beliefmedia_import_image() function
4
 Import Remote Images into WordPress and Return Image URL, Image ID, and Image Dimensions
5
 http://www.beliefmedia.com/import-remote-images-wordpress
6
 http://www.beliefmedia.com/code/wp-snippets/import-remote-image-demo
7
*/
8
 
9
function beliefmedia_import_image_demo($atts) {
10
 
11
  extract(shortcode_atts(array(
12
    'url' => '', /* Image URL */
13
    'description' => 'Image',
14
    'source' => 0
15
  ), $atts));
16
 
17
 /* Post ID */
18
 global $post;
19
 
20
  /* DB Image hash */
21
  $hash = 'wp_imp_' . md5($url);
22
 
23
  if ( (get_post_meta($post->ID, $hash, true)) != '') {
24
   $temp = get_post_meta($post->ID, $hash, true);
25
 
26
   } else {
27
 
28
    $temp = beliefmedia_import_image($url, $description, $src = 0);
29
    add_post_meta($post->ID, $hash, $temp);
30
 
31
   }
32
 
33
  /* Return image string or array? */
34
  $result = ($source) ? (string) $temp['html'] : 'pre' . print_r($temp, true) . '/pre';
35
 
36
 return $result;
37
}
38
add_shortcode('importimagedemo', 'beliefmedia_import_image_demo');

The function is for demonstration purposes only and will require modification before it can be applied in any practical way. That said, you can use it to return the image as follows:

1
<img src='https://www.beliefmedia.com.au/wp-content/uploads/2017/09/logo-2.png'>

The result:

Of course you'll also need our beliefmedia_import_image() function. The source article provides further detail.

■ ■ ■

 
Download our complimentary 650-page guide on marketing for mortgage brokers. We'll show you exactly how we generate billions in volume for our clients.
Finance Guide, Cropped Top and Bottom
  Timezone: 1 · [ CHANGE ]

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment