Home / Admin / Rank Math
Duplicate Snippet

Embed Snippet on Your Site

Rank Math

Support for Rank Math

Code Preview
php
<?php
// Change OG title for Rank Math on Vendor Pages
function wcv_rankmath_change_og_title( $title ) {
	WC_Vendors::log( $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( 'rank_math/frontend/title', 'wcv_rankmath_change_og_title' );
// Change Meta description for Rank Math on Vendor Pages
function wcv_rankmath_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( 'rank_math/frontend/description', 'wcv_rankmath_change_meta_description' );
// Change OG description for Rank Math on Vendor Pages
function wcv_rankmath_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( 'rank_math/frontend/description', 'wcv_rankmath_change_og_description' );
// Change OG image for Rank Math on Vendor Pages
function wcv_rankmath_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( 'rank_math/opengraph/facebook/image', 'wcv_rankmath_change_og_image' );
add_filter( 'rank_math/opengraph/twitter/image', 'wcv_rankmath_change_og_image' );
// Change OG URL for Rank Math on Vendor Pages.
function wcv_rankmath_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( 'rank_math/opengraph/url', 'wcv_rankmath_change_og_url' );

Comments

Add a Comment