時間:2023-06-13 11:33:01 | 來源:網(wǎng)站運營
時間:2023-06-13 11:33:01 來源:網(wǎng)站運營
WP網(wǎng)站模板開發(fā)中,怎樣給分類目錄添加SEO標(biāo)題和關(guān)鍵詞?:作為一個wordpress網(wǎng)站的站長,都希望自己的網(wǎng)站在百度或谷歌搜索引擎上的排名好。這時,我們除了要做好wordpress網(wǎng)站的內(nèi)容之外,還要對wordpress網(wǎng)站做好相關(guān)的SEO優(yōu)化。在前面的章節(jié)中,我們介紹了wordpress網(wǎng)站首頁的SEO優(yōu)化,今天,我們再來介紹一下wordpress網(wǎng)站的分類目錄頁面的SEO優(yōu)化。//給分類目錄添加 SEO標(biāo)題、關(guān)鍵詞、描述//添加頁面 掛載字段add_action( 'category_add_form_fields', 'category_term_field' );//分類add_action( 'post_tag_add_form_fields', 'category_term_field' );//標(biāo)簽function category_term_field() {wp_nonce_field( basename( __FILE__ ), 'category_term_field_nonce' );//wp_enqueue_script('dreamc_term_fields', get_template_directory_uri(). '/js/termmeta-upload.js');echo '<div class="form-field category-term-field">';echo '<label for="category-term-seo_title">SEO標(biāo)題</label>';echo '<input type="text" name="category_term_seo_title" id="category-term-seo_title" value="" />';echo '</div>';echo '<div class="form-field category-term-field">';echo '<label for="category-term-seo_keywords">SEO關(guān)鍵詞</label>';echo '<textarea name="category_term_seo_keywords" id="category-term-seo_keywords"></textarea>';echo '</div>';echo '<div class="form-field category-term-field">';echo '<label for="category-term-seo_description">SEO描述</label>';echo '<textarea name="category_term_seo_description" id="category-term-seo_description"></textarea>';echo '</div>';}這時,我們再到后臺去看一下“添加新分類目錄”界面,效果如下圖:
//分類擴(kuò)展信息 編輯界面add_action( 'category_edit_form_fields', 'edit_category_term_field' );//分類add_action( 'post_tag_edit_form_fields', 'edit_category_term_field' );//標(biāo)簽function edit_category_term_field( $term ) {//獲取數(shù)據(jù)$category_title = get_term_meta( $term->term_id, 'category_seo_title', true );$category_keywords = get_term_meta( $term->term_id, 'category_seo_keywords', true );$category_des = get_term_meta( $term->term_id, 'category_seo_des', true );echo '<tr class="form-field category-term-field-wrap">';echo '<th scope="row"><label for="category-term-title">SEO標(biāo)題</label></th>';echo '<td>';echo wp_nonce_field( basename( __FILE__ ), 'category_term_field_nonce' );echo '<input type="text" name="category_term_title" id="category-term-title" value="'.$category_title.'"/>';echo '</td>';echo '</tr>';echo '<tr class="form-field category-term-field-wrap">';echo '<th scope="row"><label for="category-term-keywords">SEO關(guān)鍵詞</label></th>';echo '<td>';echo '<textarea name="category_term_keywords" id="category-term-keywords">'.$category_keywords.'</textarea>';echo '</td>';echo '</tr>';echo '<tr class="form-field category-term-field-wrap">';echo '<th scope="row"><label for="category-term-des">SEO描述</label></th>';echo '<td>';echo '<textarea name="category_term_des" id="category-term-des">'.$category_des.'</textarea>';echo '</td>';echo '</tr>';}我們再到后臺的分類目錄編輯界面看一下,效果如下圖:
//保存數(shù)據(jù)add_action( 'create_category', 'save_category_term_field' );add_action( 'edit_category', 'save_category_term_field' );//分類add_action( 'create_post_tag', 'save_category_term_field' );add_action( 'edit_post_tag', 'save_category_term_field' );//標(biāo)簽function save_category_term_field( $term_id ) {if ( ! isset( $_POST['category_term_field_nonce'] ) || ! wp_verify_nonce( $_POST['category_term_field_nonce'], basename( __FILE__ ) ) )return;//獲取$category_title = isset( $_POST['category_term_title'] ) ? $_POST['category_term_title'] : '';$category_keywords = isset( $_POST['category_term_keywords'] ) ? $_POST['category_term_keywords'] : '';$category_des = isset( $_POST['category_term_des'] ) ? $_POST['category_term_des'] : '';//更新if( '' === $category_title){delete_term_meta( $term_id, 'category_seo_title' );}else{update_term_meta( $term_id, 'category_seo_title', $category_title );}if( '' === $category_keywords){delete_term_meta( $term_id, 'category_seo_keywords' );}else{update_term_meta( $term_id, 'category_seo_keywords', $category_keywords );}if( '' === $category_des){delete_term_meta( $term_id, 'category_seo_des' );}else{update_term_meta( $term_id, 'category_seo_des', $category_des );}}通過上面幾步,我們就為我們的wordpress網(wǎng)站的分類目錄添加了SEO標(biāo)題、關(guān)鍵詞、描述的功能,以后,我們在添加分類目錄時,填寫這些信息,然后,再在前臺模板的頭部調(diào)用,就可以實現(xiàn)wordpress網(wǎng)站分類目錄頁面的SEO優(yōu)化了。
關(guān)鍵詞:目錄,標(biāo)題,關(guān)鍵,分類,模板,怎樣
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。