$og_title = '';
$og_desc = '';
$og_url = '';
$og_image = 'https://www.htsteker.com/wp-content/uploads/2023/12/logo.png'; // varsayılan görsel
if ( is_front_page() || is_home() ) {
$og_title = get_bloginfo('name');
$og_desc = get_bloginfo('description');
$og_url = home_url('/');
} elseif ( is_singular() ) {
global $post;
$og_title = get_the_title($post->ID);
$og_desc = get_the_excerpt($post->ID);
if ( empty($og_desc) ) {
$og_desc = wp_strip_all_tags( wp_trim_words( get_post_field('post_content', $post->ID), 30, '...' ) );
}
$og_url = get_permalink($post->ID);
if ( has_post_thumbnail($post->ID) ) {
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
if ( ! empty($thumb[0]) ) {
$og_image = $thumb[0];
}
}
} elseif ( is_category() || is_tag() || is_tax() ) {
$og_title = single_term_title('', false);
$og_desc = term_description();
if ( empty($og_desc) ) {
$og_desc = get_bloginfo('description');
} else {
$og_desc = wp_strip_all_tags($og_desc);
}
$og_url = get_term_link(get_queried_object());
} elseif ( is_post_type_archive() ) {
$og_title = post_type_archive_title('', false);
$og_desc = get_bloginfo('description');
$og_url = get_post_type_archive_link( get_post_type() );
} else {
$og_title = wp_get_document_title();
$og_desc = get_bloginfo('description');
$og_url = home_url( add_query_arg([], $wp->request ?? '') );
}
$og_title = wp_strip_all_tags($og_title);
$og_desc = wp_strip_all_tags($og_desc);
$og_url = esc_url($og_url);
$og_image = esc_url($og_image);
?>