How to use yoast seo breadcrumb with anspress?

Solved5.33K viewsIssues

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.

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;
commented on answer

This works great, thanks for sharing.

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.

I have added that to my todo list, when I have time I will add that to the filter example above.

Much appreciated!


Why don’t you use Anspress breadcrumbs that seem to work fine ?


(fine, apart from the fact that they show a truncated title/url for long titles)

commented on answer

Because Yoast adds extra seo functionality to the html. And it works side wide.

Yoast adds also a lot of load to the site. For me all those “SEO” plugins are just crapola. They add nothing actually. Hoax.

Yoast SEO is not a magic bullet, but it has a few great tools. One of which is the breadcrumb.

AnsPress does not have the best breadcrumb widget.

There are a few posts here where people have the same problem as I have. Some are pretty old, but they appear unanswered.

After a debug I can tell why this has not been answered. Since AnsPress use the same base page, yoast seo sees the page id as the endpoint for the breadcrumb, so the breadcrumb never changes for all sub url’s

Sure you can change the page title in a filter, but that does not give you a correct breadcrumb, since it should display the base_page / title of the question

Instead it displays title of the base_page always.