2016-05-19 10 views
0

特定のカテゴリのWordPress URLからカテゴリベースを削除したいと思います。 mysite.com/category/blog にmysite.com/blog特定のカテゴリのWordPress URLからカテゴリベースを削除する

しかし、私はそのまま他のカテゴリを維持したい: はたとえば、私は変更する必要が mysite.com/category/songs

私はそれがいくつかの.htaccessルールで達成できると思いますが、すべてのURLで基本カテゴリを削除するいくつかの一般的なルールが見つかりました。

答えて

2

あなたはEnhanced Custom Permalinks Wpプラグインを使って簡単にこれを達成できます。あなたはちょうどカテゴリを編集する必要があります、あなたのカスタムURLを追加するフィールドが表示されます。

https://wordpress.org/plugins/enhanced-custom-permalinks/

0

あなたは簡単にプラグインを使用せずにそれを行うことができます。管理パネル を通じて これは、いくつかのカスタムフィルタ&アクションを行うことができ https://codex.wordpress.org/Using_Permalinks

+0

、してください質問を読む –

+0

他の解決策は私の2番目の答えにあります。ここにあるのは https://wordpress.org/support/topic/change-permalink-for-one-category-only –

2

..あなたがより多くを知っているここ

カスタム

にデフォルトを>設定パーマリンクを選択して行きます。 テーマののfunctions.phpファイルにこのコードを配置してみてください。

add_filter('post_link', 'custom_permalink', 10, 3); 
function custom_permalink($permalink, $post, $leavename) { 
    // Get the categories for the post 
    $category = get_the_category($post->ID); 
    if ( !empty($category) && $category[0]->cat_name == "News") { 
     $permalink = trailingslashit(home_url('/'. $post->post_name .'-'. $post->ID .'/')); 
    } 
    return $permalink; 
} 
add_action('generate_rewrite_rules', 'custom_rewrite_rules'); 
function custom_rewrite_rules($wp_rewrite) { 
    // This rule will will match the post id in %postname%-%post_id% struture 
    $new_rules['^([^/]*)-([0-9]+)/?'] = 'index.php?p=$matches[2]'; 
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; 
    return $wp_rewrite; 
} 

これあなたが投稿をしたいパーマリンク構造を設定します:

彼がすべてではないため、唯一の特定のカテゴリに変更したい
関連する問題