Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
2.9 kB
3
Indexable
Never
// Customize Open Graph tags and SEO Title for Vendor Store Pages with ACF fields
add_action('wp_head', 'marketking_custom_og_data_for_vendor_acf', 1);
add_filter('pre_get_document_title', 'marketking_custom_seo_title_for_vendor_acf', 1000);
add_filter('rank_math/frontend/title', 'marketking_override_rankmath_title', 1000);

function marketking_override_rankmath_title($title) {
    if ( function_exists('marketking') && marketking()->is_vendor_store_page() ) {
        // Empty title to override Rank Math title
        return '';
    }
    return $title;
}

function marketking_custom_og_data_for_vendor_acf() {
    if ( function_exists('marketking') && marketking()->is_vendor_store_page() ) {
        $vendor_id = marketking()->get_vendor_id_in_store_url();
        
        if ($vendor_id !== 0) {
            // Retrieve data from ACF fields
            $store_name = do_shortcode('[vendor_marketking_store_name]');
            $store_url = do_shortcode('[vendor_marketking_store_url]');
            $store_logo = do_shortcode('[vendor_marketking_profile_logo_image]');
            $store_banner = do_shortcode('[vendor_marketking_profile_logo_image_banner]');
            $store_description = do_shortcode('[vendor_marketking_store_aboutus]');
            
            // Set OG:title and OG:description
            echo '<meta property="og:title" content="' . esc_attr($store_name) . ' - ' . get_bloginfo('name') . '" />' . "\n";
            echo '<meta property="og:description" content="' . esc_attr($store_description) . '" />' . "\n";
            
            // Set OG:url
            echo '<meta property="og:url" content="' . esc_url($store_url) . '" />' . "\n";
            
            // Set OG:image (use banner if available, otherwise logo)
            if (!empty($store_banner)) {
                echo '<meta property="og:image" content="' . esc_url($store_banner) . '" />' . "\n";
            } elseif (!empty($store_logo)) {
                echo '<meta property="og:image" content="' . esc_url($store_logo) . '" />' . "\n";
            }

            // Set OG:image:alt
            echo '<meta property="og:image:alt" content="' . esc_attr($store_name) . '" />' . "\n";

            // Set OG:type
            echo '<meta property="og:type" content="website" />' . "\n";
        }
    }
}

function marketking_custom_seo_title_for_vendor_acf($title) {
    if ( function_exists('marketking') && marketking()->is_vendor_store_page() ) {
        $vendor_id = marketking()->get_vendor_id_in_store_url();
        
        if ($vendor_id !== 0) {
            // Retrieve vendor store name
            $store_name = do_shortcode('[vendor_marketking_store_name]');
            
            // Set title as "[Vendor Name] - [Site Title]"
            $title = $store_name . ' - ' . get_bloginfo('name');
        }
    }
    return $title;
}
Leave a Comment