HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/insiders/wp-load/wp-content/plugins/gutenmate/lib/seo.php
<?php

/*//////////////////////////////////////
// Add Schema to Site Header
//////////////////////////////////////*/

add_action( 'wp_head', 'gtm_the_schema_header_meta' );
function gtm_the_schema_header_meta() {

	if ( is_front_page() && get_option( 'gtm_seo_enable_title_meta', true ) ) {
		?><meta name="description" content="<?php echo esc_attr( get_bloginfo( 'description' ) ); ?>"><?php

	} else if ( is_singular() ) {

		setup_postdata( get_post( get_queried_object_id() ) );
		$img_url = wp_get_attachment_url( get_post_thumbnail_id() );

		?>

		<?php if ( get_option( 'gtm_seo_enable_title_meta', true ) ): ?>
			<!-- Primary meta tags -->
			<meta name="title" content="<?php the_title_attribute();?>">
			<meta name="description" content="<?php echo esc_attr( get_the_excerpt() ); ?>">
		<?php endif;?>

		<?php if ( get_option( 'gtm_seo_enable_facebook_meta', true ) ): ?>
			<!-- Open Graph / Facebook -->
			<meta property="og:type" content="article">
			<meta property="og:url" content="<?php echo esc_url( get_the_permalink() ); ?>">
			<meta property="og:title" content="<?php the_title_attribute();?>">
			<meta property="og:description" content="<?php echo esc_attr( get_the_excerpt() ); ?>">
			<meta property="og:image" content="<?php echo esc_url( $img_url ); ?>">
		<?php endif;?>

		<?php if ( get_option( 'gtm_seo_enable_twitter_meta', true ) ): ?>
			<!-- Twitter -->
			<meta property="twitter:card" content="summary_large_image">
			<meta property="twitter:url" content="<?php echo esc_url( get_the_permalink() ); ?>">
			<meta property="twitter:title" content="<?php the_title_attribute();?>">
			<meta property="twitter:description" content="<?php echo esc_attr( get_the_excerpt() ); ?>">
			<meta property="twitter:image" content="<?php echo esc_url( $img_url ); ?>">
		<?php endif;?>

		<?php

		if ( get_option( 'gtm_seo_enable_post_rich_snippets', true ) ) {
			gtm_the_publisher_schema();
			gtm_the_author_schema();
			gtm_the_post_schema();
		}

		wp_reset_postdata();
	}
}

/*//////////////////////////////////////
// Publisher Schema
//////////////////////////////////////*/

function gtm_the_publisher_schema() {
	$json = [
		'@context' => 'http://schema.org/',
		'@id'      => '#Publisher',
		'@type'    => 'Organization',
		'name'     => get_bloginfo( 'name' ),
		'url'      => home_url( '/' ),
		'logo'     => [
			'@type' => 'ImageObject',
			'url'   => wp_get_attachment_url( get_theme_mod( 'custom_logo' ) ) ?: '',
		],
	];

	// Render
	echo '<script type="application/ld+json">';
	echo wp_json_encode( apply_filters( 'gtm_the_publisher_schema', $json ), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
	echo '</script>';
}

/*//////////////////////////////////////
// Author Schema
//////////////////////////////////////*/

function gtm_the_author_schema( $post_id = '' ) {
	if ( empty( $post_id ) ) {
		$post_id = get_queried_object_id();
	}

	$post = get_post( $post_id );

	$json = [
		'@context' => 'http://schema.org/',
		'@id'      => '#Author',
		'@type'    => 'Person',
		'name'     => get_the_author_meta( 'display_name', $post->post_author ),
		'image'    => get_avatar_url( $post->post_author ),
		'url'      => get_author_posts_url( $post->post_author ),
	];

	// Render
	echo '<script type="application/ld+json">';
	echo wp_json_encode( apply_filters( 'gtm_the_author_schema', $json ), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
	echo '</script>';
}

/*//////////////////////////////////////
// Post Schema
//////////////////////////////////////*/

function gtm_the_post_schema( $post_id = '' ) {
	if ( empty( $post_id ) ) {
		$post_id = get_queried_object_id();
	}

	$post               = get_post( $post_id );
	$clean_post_content = wp_strip_all_tags( strip_shortcodes( $post->post_content ), true );

	$json = [
		'@context'           => 'http://schema.org/',
		'@type'              => 'NewsArticle',
		'dateCreated'        => get_the_date( 'c' ),
		'datePublished'      => get_the_date( 'c' ),
		'dateModified'       => get_the_modified_date( 'c' ),
		'name'               => get_the_title( $post ),
		'headline'           => get_the_title( $post ),
		'url'                => get_permalink( $post ),
		'description'        => wp_html_excerpt( $clean_post_content, 200 ),
		'copyrightYear'      => get_the_time( 'Y' ),
		'keywords'           => wp_strip_all_tags( get_the_tag_list( '', ',', '' ), true ),
		'articleSection'     => wp_strip_all_tags( get_the_category_list( '', ',', '' ), true ),
		'articleBody'        => $clean_post_content,
		'mainEntityOfPage'   => [
			'@type' => 'WebPage',
			'@id'   => get_permalink( $post ),
		],
		'publisher'          => [
			'@id' => '#Publisher',
		],
		'sourceOrganization' => [
			'@id' => '#Publisher',
		],
		'copyrightHolder'    => [
			'@id' => '#Publisher',
		],
		'author'             => [
			'@id' => '#Author',
		],
	];

	if ( has_post_thumbnail( $post ) ) {
		$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post ), 'full' );

		$json['image'] = [
			'@type'  => 'ImageObject',
			'url'    => $img_src[0],
			'width'  => $img_src[1],
			'height' => $img_src[2],
		];
	}

	// Render
	gtm_the_json_ld( apply_filters( 'gtm_the_post_schema', $json ) );
}

function gtm_the_json_ld( $json ) {
	echo '<script type="application/ld+json">';
	echo wp_json_encode( $json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
	echo '</script>';
}

function gtm_get_item_list_schema( $data, $options = [] ) {
	$options = wp_parse_args( $options, [
		'main_type' => 'ItemList',
		'item_type' => 'ListItem',
		'id'        => '',
	] );

	if ( empty( $data ) || ! is_array( $data ) ) {
		return;
	}

	$json = [
		'@context'        => 'http://schema.org/',
		'@type'           => $options['main_type'],
		'itemListElement' => $data,
	];

	if ( ! empty( $options['id'] ) ) {
		$json['@id'] = $options['id'];
	}

	return $json;
}