I would like to assign a picture URL via PHP to a page. I’ve googled already but just found something like this:
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):
1 Answer
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.