简体   繁体   中英

Python WordPress REST API - Post Featured Image as external URL

is it possibile to post in wordpress the featured image as hotlink (external url), without hosting the image on the server?

See the line that should be fixed:

"featured_image": 'https://upload.wikimedia.org/wikipedia/it/f/fc/Pippo_Disney.png'

in

postDict = {
    "title": 'Hi',
    "content": 'My Content',
    "date": '2020-08-17T10:16:34',
    "featured_image": 'https://upload.wikimedia.org/wikipedia/it/f/fc/Pippo_Disney.png', # IMPORTANT
}

If it is not possibile, any ideas to do that is really welcome, thank you

By default, WordPress doesn't support external links for featured images. However, there're some plugins implementing this feature:

You'll have to research their source code to understand how to use them from the REST API.

There is a simple trick for this. You can paste a link for external img for example to excerpt, and then you can get this url by using get_the_excerpt https://developer.wordpress.org/reference/functions/get_the_excerpt/ . In posts listing use

<img src="<?php echo get_the_excerpt( $post_id ); ?>">

Just insert image as HTML and it will auto-make it the featured image "<img src={img} width="900" height="400" />"

https://wordpress.org/plugins/auto-post-thumbnail/ (Use old version of plugin, New version is broken)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM