Home > other >  Python WordPress REST API - Post Featured Image as external URL
Python WordPress REST API - Post Featured Image as external URL

Time:01-15

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

CodePudding user response:

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.

CodePudding user response:

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 ); ?>">
  •  Tags:  
  • Related