0

i have add facebook opengraph tag

now it showing error like

Call to undefined function wp_get_attachment_src()

Object at URL 'http://www.website.com' of type 'article' is invalid because the given value ': Call to undefined function wp_get_attachment_src() in on line Fatal error ...... functions.php123 ' for property 'og:image:url' could not be parsed as type 'url'.

using this code in header.php

<meta property="og:image" content="<?php echo get_fbimage(); ?>" />

in function.php

<?php
function get_fbimage() {
$src = wp_get_attachment_src( get_post_thumbnail_id($post->ID), '', '' );
if ( has_post_thumbnail($post->ID) ) {
$fbimage = $src[0];
} else {
global $post, $posts;
$fbimage = '';
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i',
$post->post_content, $matches);
$fbimage = $matches [1] [0];
}
if(empty($fbimage)) {
$fbimage = "http://www.gogirlfinance.com/wp-content/uploads/2011/03/logo.jpg";
}
return $fbimage;
}
?>

Note: I am using same code/ function in other website with no issue

1

I think you are looking for wp_get_attachment_image_src instead of wp_get_attachment_src which is not a core WordPress function

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.