36 lines
1.9 KiB
PHP
36 lines
1.9 KiB
PHP
<?php
|
|
function add_opengraph_tags() {
|
|
$author_id = get_option('sophia_after_dark_home_og_user', 1); // Default to user ID 1 if not set
|
|
|
|
$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');
|