Implement automatic OpenGraph tags population
This commit is contained in:
parent
4231dab898
commit
aa75f2f60f
|
@ -8,19 +8,18 @@ add_filter( 'the_excerpt', 'shortcode_unautop');
|
|||
add_filter( 'the_excerpt', 'do_shortcode');
|
||||
|
||||
// OpenGraph image for FB/Twitter
|
||||
// TODO: less hacky solution
|
||||
function og_image( $tags ) {
|
||||
$og_image = esc_url("https://www.openfest.org/2023/wp-content/uploads/sites/27/2023/09/2023_fb_preview.jpg");
|
||||
$imagePath = __DIR__ . '/img/' . $blog_slug . '_fb_preview.jpg';
|
||||
|
||||
unset( $tags['og:image'] );
|
||||
$tags['og:image'] = $og_image;
|
||||
unset( $tags['og:image:width'] );
|
||||
$tags['og:image:width'] = 678;
|
||||
unset( $tags['og:image:height'] );
|
||||
$tags['og:image:height'] = 260;
|
||||
if (file_exists($imagePath)) {
|
||||
$imageUrl = esc_url('https://www.openfest.org/wp-content/themes/initfest/img/' . basename($imagePath));
|
||||
list($width, $height) = getimagesize($imagePath);
|
||||
|
||||
unset( $tags['twitter:image'] );
|
||||
$tags['twitter:image'] = $og_image;
|
||||
$tags['og:image'] = $imageUrl;
|
||||
$tags['og:image:width'] = $width;
|
||||
$tags['og:image:height'] = $height;
|
||||
$tags['twitter:image'] = $imageUrl;
|
||||
}
|
||||
|
||||
return $tags;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue