add Open Graph support! (that looks good XD)
This commit is contained in:
37
inc/customizer/mt-customizer-additional-open-graph.php
Normal file
37
inc/customizer/mt-customizer-additional-open-graph.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
function add_opengraph_tags() {
|
||||
// Get Sophia's user ID
|
||||
$author_id = 1; // Replace with the actual user ID of Sophia
|
||||
|
||||
// Retrieve Sophia's bio
|
||||
$author_bio = get_the_author_meta('description', $author_id);
|
||||
|
||||
if (is_front_page()) {
|
||||
$home_og_image = get_option('sophia_after_dark_home_og_image');
|
||||
if ($home_og_image) {
|
||||
echo '<meta property="og:image" content="' . esc_url($home_og_image) . '" />';
|
||||
}
|
||||
echo '<meta property="og:title" content="' . esc_attr(get_bloginfo('name') . ' - ' . get_bloginfo('description')) . '" />';
|
||||
echo '<meta property="og:description" content="' . esc_attr($author_bio) . '" />';
|
||||
echo '<meta property="og:url" content="' . esc_url(home_url('/')) . '" />';
|
||||
} elseif (is_single() || is_page()) {
|
||||
global $post;
|
||||
if (has_post_thumbnail($post->ID)) {
|
||||
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'og-image-size');
|
||||
if ($thumbnail) {
|
||||
echo '<meta property="og:image" content="' . esc_url($thumbnail[0]) . '" />';
|
||||
|
||||
//$thumbnail_url = esc_url($thumbnail[0]);
|
||||
//$thumbnail_parts = pathinfo($thumbnail_url);
|
||||
//$thumbnail_new_url = $thumbnail_parts['dirname'] . '/' . $thumbnail_parts['filename'] . '-1536x878.' . $thumbnail_parts['extension'];
|
||||
//echo '<meta property="og:image" content="' . $thumbnail_new_url . '" />';
|
||||
}
|
||||
} else {
|
||||
echo '<meta property="og:image" content="' . esc_url(get_template_directory_uri() . '/assets/images/default-og-image.webp') . '" />';
|
||||
}
|
||||
echo '<meta property="og:title" content="' . esc_attr(get_the_title()) . '" />';
|
||||
echo '<meta property="og:description" content="' . esc_attr(get_the_excerpt()) . '" />';
|
||||
echo '<meta property="og:url" content="' . esc_url(get_permalink()) . '" />';
|
||||
}
|
||||
}
|
||||
add_action('wp_head', 'add_opengraph_tags');
|
Reference in New Issue
Block a user