Get Taxonomy title structure (o wpseo title value) in a single page
-
Hi everyone,
in a single page (not an archive) I inserted a loop of products (custom post type) with ajax filters. So I have a page structure like this:
- /products
- /products?tax1=myCatSlug
- /products?tax1=myCatSlug&tax2=myTagSlug
When I first open the /products page, the page takes the title of the sigle page, and then everything is OK.
Now I would like to make the page /products?tax1=myCatSlug take the name of the taxonomy used as a filter. To make it work I do this:
add_filter( 'wpseo_title', 'SeoTitleRewriter' ); function SeoTitleRewriter($title){ if (is_page(myPageID)){ if (isset($_GET['tax1'])){ $catObj = get_term_by( 'slug', $_GET['tax1'], 'myCustomTaxSlug' ); $YoastSeoTitle = WPSEO_Taxonomy_Meta::get_term_meta( $catObj, 'myCustomTaxSlug', 'title' ); $YoastSeoTitle = wpseo_replace_vars( $YoastSeoTitle, $catObj ); return $YoastSeoTitle; } } }
This only works if I fill in the Yoast title field for each taxonomy, if I leave the default values (eg: %%term_title%% %%sep%% %%sitename%%) I can’t read them with WPSEO_Taxonomy_Meta, which replies null.
Is there any way to make Yoast’s default values (set in the related content type settings) work as well?
Thank you
- The topic ‘Get Taxonomy title structure (o wpseo title value) in a single page’ is closed to new replies.