1. Home
  2. WC Vendors Marketplace
  3. Code Snippets
  4. Vendor Description as Yoast SEO Meta on Shop Page

Vendor Description as Yoast SEO Meta on Shop Page

If you are using Yoast SEO and would like the /vendors/username meta description to be their shop description, use this snippet provided by @jetlej

/ Overwrite meta description for vendor pages
function overwrite_vendor_meta($desc) {

    // Return the default value if we're not on a vendor shop page
    if(!WCV_Vendors::is_vendor_page()) return $desc;

    // Get the vendor description and return it
    $vendor_shop = urldecode( get_query_var( 'vendor_shop' ) );
    $vendor_id   = WCV_Vendors::get_vendor_id( $vendor_shop );
    $desc = get_user_meta( $vendor_id, 'pv_shop_description', true );

    // Remove line breaks
    $desc = str_replace(array("\r", "\n"), " ", strip_tags($desc));
    // Remove extra spaces
    $desc = preg_replace( '/\s+/', ' ', $desc );
    // Escape special characters
    $desc = htmlspecialchars($desc);
    // Shorten it to 156 characters (153 + '...')
    $desc = substr($desc ,0,153).'...';

    return $desc;
}
add_filter( 'wpseo_metadesc', 'overwrite_vendor_meta', 10, 1);

filters

Updated on December 21, 2016

Was this article helpful?