未分類

wordpress使用自訂欄位完成SEO需求

編輯wp-content/themes/主題/header.php

1.加入如下字段
<?php if (is_page()){echo '<meta name="description" content="'.get_post_meta($post->ID, "description", true).'" />'."\r\n";}?>
<?php if (is_page()){echo '<meta name="keywords" content="'.get_post_meta($post->ID, "keywords", true).'" />'."\r\n";}?>

2.在新增頁面時加入自訂欄位:description、keywords即可!

 

***************************************************************************

使用自訂欄位title,如果有就使用自訂欄位的title沒有此欄位就使用原裝的設計

wp-includes/general-template.php

function _wp_render_title_tag() {
if ( ! current_theme_supports( ‘title-tag’ ) ) {
return;
}

    $l_title = get_post_meta( get_the_ID(), “title”, true);
    if($l_title == “”){
        echo ‘<title>’ . wp_get_document_title(). ‘</title>’ . “\n”;
    }else{
        echo ‘<title>’. $l_title .'</title>’.”\n”;
    }

}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。