How to use yoast seo breadcrumb with anspress?
I use yoast seo and the breadcrumbs feature on my site, but on anspress pages only the base_page is shown, so basically all pages/questions/answers/profiles etc share the same url.
How can I get this right?
I have searched and found that there areĀ 3 other questions about this but no really answers.
Does anybody have a guide on how to fix this?
I am on version 2.4.8 of Anspress.
Henrik_Gregersen selected answer
I developed a filter which will make yoast seo breadcrumb work with anspress..
add_filter( 'wpseo_breadcrumb_links' , 'myYoastAnsPressBreadCrumb');
function myYoastAnsPressBreadCrumb($breadcrumb) { global $wp_query; $workBreadcrumb = $breadcrumb; $questionId = $wp_query->get('question_id'); if (!empty($questionId)) { // We are showing a question // Test to see if the current page in the breadcrumb is the AnsPress base page if (function_exists('ap_opt')) { $lastCrumb = array_pop($workBreadcrumb); if (is_array($lastCrumb)) { if (array_key_exists('id', $lastCrumb )) { if (ap_opt('base_page') == $lastCrumb['id']) { // Change the last crump id to point to the question $parentId = $lastCrumb['id']; $lastCrumb['id'] = $questionId; // Create a listing for the base_page $workBreadcrumb[] = array( 'text' => strip_tags( get_the_title( $parentId ) ), 'url' => get_permalink($parentId), 'allow_html' => true); // Add the question as the last crumb $workBreadcrumb[] = $lastCrumb; return $workBreadcrumb; } } } } } return $breadcrumb; }
Maciek Swoboda (Buyer) commented on answer
Maciek Swoboda (Buyer) commented
It would be great to add support for Categories and Tags plugins. Right now categories/tags do not show up in breadcrumbs when visiting question page.
Henrik_Gregersen commented
I have added that to my todo list, when I have time I will add that to the filter example above.
Maciek Swoboda (Buyer) commented
Much appreciated!
This works great, thanks for sharing.