2

I would like to assign a picture URL via PHP to a page. I’ve googled already but just found something like this:

https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/

Does anyone have an idea how I can assign a picture URL to a page via PHP?

Furthermore the picture has to be integrated via the URL and not be downloaded in my media library and not be applied from there. So external.

What I mean is this here (Called Featured Image in English):

screenshot of portion of admin dashboard with relevant field highlighted in red

0

You can use the add_post_meta function:

add_post_meta( get_the_ID(), 'my_custom_image_url', 'http://domain.com/image.jpg', true );

The code above assumes that a) you will have only one image per page; and b) you are in a loop so get_the_ID will return a valid ID of the page you want to attach the meta-data to. Documentation here.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.