Home / Admin / Yoast SEO
Duplicate Snippet

Embed Snippet on Your Site

Yoast SEO

Integration with Yoast SEO with WC Vendors

Code Preview
php
<?php
// Change OG title for Yoast on Vendor Pages
function wcv_wpseo_change_og_title( $title ) {
	if ( WCV_Vendors::is_vendor_page() ) {
		$vendor_shop = urldecode( get_query_var( 'vendor_shop' ) );
		$vendor_id = WCV_Vendors::get_vendor_id( $vendor_shop );
		$shop_title = get_user_meta( $vendor_id, 'pv_shop_name', true );
		$og_title = get_user_meta( $vendor_id, 'wcv_seo_fb_title', true );
		if ( ! empty( $og_title ) ) {
			$title = $og_title;
		} else {
			$title = $shop_title;
		}
	}
	return $title;
}
add_filter( 'wpseo_opengraph_title', 'wcv_wpseo_change_og_title' );
// Change Meta description for Yoast on Vendor Pages
function wcv_wpseo_change_meta_description( $desc ) {
	if ( WCV_Vendors::is_vendor_page() ) {
		$vendor_shop = urldecode( get_query_var( 'vendor_shop' ) );
		$vendor_id   = WCV_Vendors::get_vendor_id( $vendor_shop );
		$shopdesc    = get_user_meta( $vendor_id, 'pv_shop_description', true );
		$meta_desc   = get_user_meta( $vendor_id, 'wcv_seo_meta_description', true );
		if ( ! empty( $meta_desc ) ) {
			$desc = $meta_desc;
		} else {
			$desc = $shopdesc;
		}
	}
	return $desc;
}
add_filter( 'wpseo_metadesc', 'wcv_wpseo_change_meta_description' );
// Change OG description for Yoast on Vendor Pages
function wcv_wpseo_change_og_description( $desc ) {
	if ( WCV_Vendors::is_vendor_page() ) {
		$vendor_shop = urldecode( get_query_var( 'vendor_shop' ) );
		$vendor_id   = WCV_Vendors::get_vendor_id( $vendor_shop );
		$shopdesc    = get_user_meta( $vendor_id, 'pv_shop_description', true );
		$meta_desc   = get_user_meta( $vendor_id, 'wcv_seo_meta_description', true );
		$og_desc     = get_user_meta( $vendor_id, 'wcv_seo_fb_description', true );
		if ( ! empty( $og_desc ) ) {
			$desc = $og_desc;
		} elseif (! empty( $meta_desc)) {
			$desc = $meta_desc;
		} else {
			$desc = $shopdesc;
		}
	}
	return $desc;
}
add_filter( 'wpseo_opengraph_desc', 'wcv_wpseo_change_og_description' );
// Change OG image for Yoast on Vendor Pages
function wcv_wpseo_change_og_image ( $image ) {
	if ( WCV_Vendors::is_vendor_page() ) {
		$vendor_shop = urldecode( get_query_var( 'vendor_shop' ) );
		$vendor_id   = WCV_Vendors::get_vendor_id( $vendor_shop );
		$og_image    = get_user_meta( $vendor_id, 'wcv_seo_fb_image_id', true );
		if (!empty($og_image)) {
			$image = wp_get_attachment_url( $og_image );
		}
	}
	return $image;
}
add_filter( 'wpseo_opengraph_image', 'wcv_wpseo_change_og_image' );
// Change OG URL for Yoast on Vendor Pages.
function wcv_wpseo_change_og_url ( $url ) {
	if ( WCV_Vendors::is_vendor_page() ) {
		$vendor_shop = urldecode( get_query_var( 'vendor_shop' ) );
		$vendor_id   = WCV_Vendors::get_vendor_id( $vendor_shop );
		$url         = WCV_Vendors::get_vendor_shop_page( $vendor_id );
	}
	return $url;
}
add_filter( 'wpseo_opengraph_url', 'wcv_wpseo_change_og_url' );

Comments

Add a Comment