add Open Graph support! (that looks good XD)

This commit is contained in:
2024-07-15 01:04:25 -07:00
parent ab824be92a
commit fad4f109f9
3 changed files with 42 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View 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');

View File

@ -20,10 +20,12 @@ function sophia_after_dark_customize_register( $wp_customize ) {
$wp_customize->get_section( 'background_image' )->priority = '15';
$wp_customize->get_section( 'static_front_page' )->panel = 'sophia_after_dark_general_panel';
$wp_customize->get_section( 'static_front_page' )->priority = '20';
$wp_customize->get_section( 'header_image' )->panel = 'sophia_after_dark_header_panel';
$wp_customize->get_section( 'header_image' )->priority = '5';
$wp_customize->get_section( 'header_image' )->description = __( 'Header Image for only Innerpages', 'sophia-after-dark' );
$wp_customize->add_setting('sophia_after_dark_home_og_image', array('default' => '','sanitize_callback' => 'esc_url_raw','type' => 'option',));
$wp_customize->add_control(new WP_Customize_Image_control($wp_customize, 'sophia_after_dark_home_og_image', array('label' => __('Home Page Open Graph Image', 'sophia_after_dark'),'section' => 'title_tagline','settings' => 'sophia_after_dark_home_og_image',)));
if ( isset( $wp_customize->selective_refresh ) ) {
$wp_customize->selective_refresh->add_partial( 'blogname', array(
@ -78,10 +80,8 @@ add_action( 'customize_preview_init', 'sophia_after_dark_customize_preview_js' )
*/
function sophia_after_dark_customize_backend_scripts() {
global $sophia_after_dark_theme_version;
wp_enqueue_style( 'sophia-after-dark--admin-customizer-style', get_template_directory_uri() . '/assets/css/mt-customizer-styles.css', array(), esc_attr( esc_attr( $sophia_after_dark_theme_version ) ) );
wp_enqueue_style( 'jquery-ui', esc_url( get_template_directory_uri() . '/assets/css/jquery-ui.css' ) );
wp_enqueue_script( 'sophia-after-dark--admin-customizer-script', get_template_directory_uri() . '/assets/js/mt-customizer-controls.js', array( 'jquery', 'customize-controls' ), esc_attr( $sophia_after_dark_theme_version ), true );
}
add_action( 'customize_controls_enqueue_scripts', 'sophia_after_dark_customize_backend_scripts', 10 );
@ -89,6 +89,8 @@ add_action( 'customize_controls_enqueue_scripts', 'sophia_after_dark_customize_b
/**
* Add Kirki required file for custom fields
*/
require get_template_directory() . '/inc/customizer/mt-customizer-additional-open-graph.php';
require get_template_directory() . '/inc/customizer/mt-customizer-custom-classes.php';
require get_template_directory() . '/inc/customizer/mt-customizer-panels.php';
require get_template_directory() . '/inc/customizer/mt-sanitize.php';