-
Hi! I use translatepress to translate my website into different languages. Currently, I use filters in my functions.php to insert keywords in my category and product pages schema. Can you guide me on how to dynamically insert translated keywords in different product and category pages? Here’s a filter I use for my category pages.
// add collectionpage schema to product category pages add_filter( 'rank_math/json_ld', function( $data, $jsonld ) { if( is_product_category() ) { $current_category = get_queried_object(); $category_name = single_term_title('', false); $products = get_posts( array( 'post_type' => 'product', 'numberposts' => -1, 'post_status' => 'publish', 'fields' => 'ids', 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $current_category->term_id, ) ), )); // Get the category description $category_description = term_description( $current_category->term_id, 'product_cat' ); $category_description = wp_strip_all_tags( $category_description ); // If description is empty, use a default if ( empty( $category_description ) ) { $category_description = "Explore our collection of " . $category_name; } // CollectionPage schema $collectionPage = array( '@type' => 'CollectionPage', 'name' => $category_name . ' Collection', 'description' => $category_description, 'url' => get_term_link( $current_category ), 'numberOfItems' => count( $products ), 'genre' => $category_name, 'keywords' => $category_name, 'breadcrumb' => array( '@type' => 'BreadcrumbList', 'itemListElement' => array( array( '@type' => 'ListItem', 'position' => 1, 'item' => array( '@id' => home_url(), 'name' => 'Home' ) ), array( '@type' => 'ListItem', 'position' => 2, 'item' => array( '@id' => get_permalink( wc_get_page_id( 'shop' ) ), 'name' => 'Shop' ) ), array( '@type' => 'ListItem', 'position' => 3, 'item' => array( '@id' => get_term_link( $current_category ), 'name' => $category_name ) ) ) ) ); // Replace the existing data with our CollectionPage schema $data = array( '@context' => 'https://schema.org', '@graph' => array( $collectionPage ) ); } return $data; }, 99, 2 );
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The ticket ‘Use of translated keywords in schemas’ is closed to new replies.