国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁 > 營銷資訊 > 網(wǎng)站運營 > WP網(wǎng)站模板開發(fā)中,怎樣給分類目錄添加SEO標(biāo)題和關(guān)鍵詞?

WP網(wǎng)站模板開發(fā)中,怎樣給分類目錄添加SEO標(biāo)題和關(guān)鍵詞?

時間: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)化。













我們都知道,分類目錄的標(biāo)題一般都比較短,有的只有2個字,這很利于SEO優(yōu)化,所以,我們將為wordpress網(wǎng)站的分類目錄后臺界面添加SEO標(biāo)題、關(guān)鍵詞、描述功能,這樣,我們在添加或修改分類目錄時,就可以為每一個分類目錄創(chuàng)建SEO標(biāo)題、關(guān)鍵詞和描述了。下面,就隨我一起來看看吧。具體可以觀看我在本站發(fā)表的《怎樣給wordpress網(wǎng)站的分類目錄,添加SEO標(biāo)題和關(guān)鍵詞?》視頻。

第一步:添加后臺“添加界面”。

給wordpress網(wǎng)站的后臺的“添加新分類目錄”界面,增加幾個SEO表單。“添加新分類目錄”界面默認(rèn)情況下如下圖。













把下面的代碼,放到wordpress主題的functions.php文件中。

//給分類目錄添加 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>';}
這時,我們再到后臺去看一下“添加新分類目錄”界面,效果如下圖:













第二步:后臺分類“編輯界面”添加SEO表單。

默認(rèn)情況下,wordpress后臺的分類編輯界面如下圖這樣。













我們要給這個分類編輯界面添加SEO標(biāo)題、關(guān)鍵詞、描述的表單。在wordpress主題的functions.php文件中,放入如下代碼:

//分類擴(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ù)”的代碼。

我們在wordpress網(wǎng)站后臺的分類目錄界面添加或修改數(shù)據(jù)后,我們還需要對它們進(jìn)行保存,所以,我們需要functions.php文件添加如下這段保存數(shù)據(jù)的代碼:

//保存數(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)鍵,分類,模板,怎樣

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點擊下載Chrome瀏覽器
關(guān)閉