Yoast 사이트 이동 경로에 페이지를 추가하는 방법


9

Yoasts Wordpress SEO를 사용하고 있으며 빵 부스러기를 설정했습니다. 문제는 내 페이지 설정이 다음과 같습니다.

/
/about
/blog - On this page I query the posts and display them. The posts themselves have nothing before them in the URL.

이동 경로는 다음과 같이 표시됩니다.

Home / Category / Page Title

나는 이것을 이렇게 보여주고 싶다.

Home/ Blog / Category / Page Title

이것이 가능한가?

답변:


27

수행해야 할 일반적인 원칙은 다음과 같습니다.

  1. 에 훅 wpseo_breadcrumb_links또는 wp_seo_get_bc_ancestors API 필터 .
  2. 을 사용하여 블로그 를 WordPress SEO Breadcrumb $links배열에 추가하십시오 array_splice.

이것을 테마에 넣으십시오 functions.php.

/**
 * Conditionally Override Yoast SEO Breadcrumb Trail
 * http://plugins.svn.wordpress.org/wordpress-seo/trunk/frontend/class-breadcrumbs.php
 * -----------------------------------------------------------------------------------
 */

add_filter( 'wpseo_breadcrumb_links', 'wpse_100012_override_yoast_breadcrumb_trail' );

function wpse_100012_override_yoast_breadcrumb_trail( $links ) {
    global $post;

    if ( is_home() || is_singular( 'post' ) || is_archive() ) {
        $breadcrumb[] = array(
            'url' => get_permalink( get_option( 'page_for_posts' ) ),
            'text' => 'Blog',
        );

        array_splice( $links, 1, -2, $breadcrumb );
    }

    return $links;
}

참고 : 사이트 또는 요구에 맞는 코드를 업데이트해야 할 수도 있지만 일반적인 생각은 동일합니다.


내 요구 사항에 맞게 조건부, URL 및 텍스트 값을 변경 한 후 완벽하게 작동했습니다. 감사.
— crdunst

기묘한. 이 코드는 'Category'를 이전에 추가하는 대신 'Blog'로 바꿨습니다.
— Michael Rogers

고정 : 내 경우에는 "1, -2"대신 "2, -3"이 필요한 이유는 확실하지 않지만 그렇게 작동합니다.
— 마이클 로저스

@ rjb 감사합니다, 매우 유용한 코드! 페이지를 제거하는 대신 트레일에 페이지를 추가하는 방법을 알고 있습니까?
— Cray
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.