導讀:建站技術建站技術我們都知道,WordPress文章作者的存檔頁面地址都是類似?http://domain.com/author/cmhello?這樣的,在用戶名前面會添加“au網站平臺搭建建站技術步梁。

我們都知道,WordPress文章作者的存檔頁面地址都是類似?http://domain.com/author/cmhello?這樣的,在用戶名前面會添加“author”前綴。今天就分享下更改或者移除這個前綴的方法。
更改作者存檔前綴 author
比如將?http://domain.com/author/cmhello?修改為?http://domain.com/profile/cmhello?樣式,并且支持作者存檔頁面的Feed輸出。
將下面的代碼添加到當前主題的 functions.php 即可:
//更改作者存檔前綴?
add_action('init',?'mbxzb_change_author_base');
function?mbxzb_change_author_base()?{
????global?$wp_rewrite;
????$author_slug?=?'profile';?//?更改前綴為?profile
????$wp_rewrite->author_base?=?$author_slug;
}
上面的代碼就將前綴 author 更改為 profile 了,請根據自己夢織模板的實際,修改第 5行的前綴。
參考資料:http://wp-snippet.com/snippets/change-the-author-slug-url-base/
注:如果添加代碼后,訪問新的存檔地址出現 404 錯誤,請訪問WP后臺 >設置>固定鏈接,重新保存一次即可。下同。
移除作者存檔前綴 author
將原來的?http://domain.com/author/cmhello? 修改為?http://domain.com/cmhello?,并且支持作者存檔頁面的Feed輸出。
//通過 author_rewrite_rules 鉤子添加新的重寫規則
add_filter('author_rewrite_rules', 'no_author_base_rewrite_rules');
function no_author_base_rewrite_rules($author_rewrite) {
global $wpdb;
$author_rewrite = array();
$authors = $wpdb->get_results("SELECT user_nicename AS nicename from $wpdb->users"); dede后臺模板;
foreach($authors as $author) {
$author_rewrite["({$author->nicename})/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$"] = 'index.php?author_name=$matches[1]&feed=$matches[2]';
$author_rewrite["({$author->nicename})/page/?([0-9]+)/?$"] = 'index.php?author_name=$matches[1]&paged=$matches[2]';
$author_rewrite["({$author->nicename})/?$"] =dede手機模板 'index.php?author_name=$matches[1]';
關鍵詞標簽: 建站 前綴 移除
聲明: 本文由我的SEOUC技術文章主頁發布于:2023-07-23 ,文章更改/移除WordPress作者存檔頁面的前綴“author”主要講述前綴,移除,建站網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_35329.html