[英]Rewrite rules for URL prefixes
我在Wordpress插件中重寫了一些URL前綴(即類別前綴,標簽前綴或自定義分類前綴)。 我正在使用Wordpress的重寫API :
add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
add_filter('init','flushRules');
// Remember to flush_rules() when adding rules
function flushRules(){
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
// Adding a new rule
function wp_insertMyRewriteRules($rules)
{
$newrules = array();
$newrules['kategorie/(.+?)/?$'] = 'index.php?category_name=$matches[1]';
return $newrules + $rules;
}
它正在運行,但是站點上的系統URL尚未更改,並且WP使用的是數據庫中的舊前綴“類別”。 我也該如何重寫這些URL?
如果要更改所有類別的永久鏈接結構,則可以在設置->永久鏈接->類別庫中進行配置 。
如果您只想更改一個或幾個類別的鏈接,則可以使用WordPress category_link過濾器:
function update_permalink( $permalink, $cat_id ) {
// If $cat_id is category we want to change, modify $permalink
return $permalink;
}
add_filter( 'category_link', 'update_permalink', 11, 2 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.