F
F
feniksdv2018-06-23 07:50:32
WordPress
feniksdv, 2018-06-23 07:50:32

How to get the url of the loaded image media_sideload_image?

<?php

require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/image.php';

$url = 'http://s.w.org/style/images/wp-header-logo.png';
$img_tag = media_sideload_image( $url, $post_id = '', $desc = '' );

if( is_wp_error($img_tag) ){
    echo $img_tag->get_error_message();
}
else {
    echo '<br>Добавлено';
    echo '<br>';
    echo $img_tag ;
}

?>

How to pull out the url of the uploaded image? echo $img_tag ;so it seems the picture itself, which has the address that I need. As an option jqvery pick up, but it's a crutch! In general, I'm struggling for a long time, help ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
feniksdv, 2018-06-28
@feniksdv

Like this:

$img_tag = media_sideload_image( $url, $post_id = '', $desc = '', 'src' );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question