Yoast meta 수정

구글 포토 플러그인 : Google Photos & Picasa Viewer

사용시 앨범 상세 보기 페이지에서 Yoast 정보가 제대로 설정 되지 않아 아래와 같이 수정

/*
#1 페이지 meta - title 수정
*/
function get_cws_album_title() {
    if( is_page() && isset( $_GET['cws_album_title'] ) ){
        return $_GET['cws_album_title'];
    }else{
        return '';
    }

}
function register_custom_yoast_variables() {
    wpseo_register_var_replacement( '%%cws_album_title%%', 'get_cws_album_title', 'advanced', 'some help text' );
}
// Add action
add_action('wpseo_register_extra_replacements', 'register_custom_yoast_variables');


/* 
#2 og:url 수정 - querystring 추가 
*/
add_filter( 'wpseo_opengraph_url', 'my_opengraph_url' );
function my_opengraph_url( $url ) {
    //return str_replace( 'https://', 'http://', $url );
    if( is_page() && isset( $_GET['cws_album_title'] ) ){
        return $url . '?cws_album=' . $_GET['cws_album'] . '&cws_album_title=' . $_GET['cws_album_title'];
    }else{
        return $url;
    }
}

/* 
#3 canonical url - 수정 
*/
add_filter( 'wpseo_canonical', 'my_wpseo_canonical' );
function my_wpseo_canonical( $url ) {
    //return str_replace( 'https://', 'http://', $url );
    if( is_page() && isset( $_GET['cws_album_title'] ) ){
        return $url . '?cws_album=' . $_GET['cws_album'] . '&cws_album_title=' . $_GET['cws_album_title'];
    }else{
        return $url;
    }
}

#2 번의 페이지 타이틀 수정을 위해 Yoast 셋팅 부분에 다음과 같이 추가

SEO > Titles & Metas > Post Types > Pages (page)

%cws_album_title% 추가

 

* 결과

목록 :  https://www.kpopidolprofile.com/photos/

상세 : https://www.kpopidolprofile.com/photos-detail/?cws_album=6507384456798008801&cws_album_title=TRCNG%20Showcase%20%28180104%29%20%231

<title>Photos detail - KPOP Idol Profiles TRCNG Showcase (180104) #1</title>
<script>document.documentElement.className = document.documentElement.className.replace("no-js","js");</script>

<meta name="description" content="Photos detail - KPOP Idol Profiles TRCNG Showcase (180104) #1" />
<meta name="keywords" content="kpop idol showcase photos" />
<link rel="canonical" href="https://www.kpopidolprofile.com/photos-detail/?cws_album=6507384456798008801&cws_album_title=TRCNG%20Showcase%20(180104)%20#1" />
<meta property="og:locale" content="en_US" />
<meta property="og:type" content="article" />
<meta property="og:title" content="Photos detail - KPOP Idol Profiles TRCNG Showcase (180104) #1" />
<meta property="og:description" content="Photos detail - KPOP Idol Profiles TRCNG Showcase (180104) #1" />
<meta property="og:url" content="https://www.kpopidolprofile.com/photos-detail/?cws_album=6507384456798008801&#038;cws_album_title=TRCNG%20Showcase%20(180104)%20#1?cws_album=6507384456798008801&#038;cws_album_title=TRCNG%20Showcase%20(180104)%20#1" />
<meta property="og:site_name" content="KPOP Idol Profiles" />
<meta property="article:publisher" content="https://www.facebook.com/Kpop-idol-profile-1999880773560197" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:description" content="Photos detail - KPOP Idol Profiles TRCNG Showcase (180104) #1" />
<meta name="twitter:title" content="Photos detail - KPOP Idol Profiles TRCNG Showcase (180104) #1" />

 

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다