I have a problem with function which get open graph meta from url:
function post_updated_set_og_description( $post_id ) {
$url = get_field('link', $post_id);
$page_content = file_get_contents($url);
$dom_obj = new DOMDocument();
@$dom_obj->loadHTML($page_content);
$meta_val = null;
foreach($dom_obj->getElementsByTagName('meta') as $meta) {
if($meta->getAttribute('property')=='og:description'){
$meta_val = $meta->getAttribute('content');
}
update_post_meta($post_id, 'og_desc', $meta_val);
}}
add_action( 'save_post', 'post_updated_set_og_description' );
It's working on localhost, but when i move my website on server it doesn't work. I have erroe sth like this:
Warning: file_get_contents($url): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in ...
I don't know how to fix it