2016-01-04 83 views
0

在我的WordPress网站的设置中,我需要发布固定链接看起来像“zzzz.com/sample-post/”。然而,我的网站使用自定义帖子,因此我下载了插件'从自定义帖子类型中删除子弹',但是所有帖子仍然以格式“zzzz.com/format/category/sample-post/”出现。我想从网址中删除'format/category'部分。只是想知道是否有另一个类似的插件,以消除这一点,或者如果我需要手动输入一些代码?如何删除URL中的“格式/类别”永久链接?

回答

0

在wp-admin中,转到以下菜单:Settings - >Permalinks。您现在处于固定链接页面,请选择Post name选项。您也可以玩Custom Structure选项。

+0

这是我做的第一件事,但无论我输入什么,自定义帖子仍然以“zzzz.com/format/category/sample-post/”格式显示但我希望它们出现如下所示:“zzzz.com/sample-post/” – Sam

1

首先禁用你安装的插件!

设置自定义结构:/%postname%/

设定的分类基础:. (dot not /)

之前使用的变化your_post_type试试这个到您的文章类型

function firefog_remove_cpt_slug($post_link, $post, $leavename) { 

    if (! in_array($post->post_type, array('your_post_type')) || 'publish' != $post->post_status) 
     return $post_link; 

    $post_link = str_replace('/' . $post->post_type . '/', '/', $post_link); 

    return $post_link; 
} 
add_filter('post_type_link', 'firefog_remove_cpt_slug', 10, 3); 

function firefog_parse_request_tricksy($query) { 

    // Only noop the main query 
    if (! $query->is_main_query()) 
     return; 

    // Only noop our very specific rewrite rule match 
    if (2 != count($query->query) 
     || ! isset($query->query['page'])) 
     return; 

    // 'name' will be set if post permalinks are just post_name, otherwise the page rule will match 
    if (! empty($query->query['name'])) 
     $query->set('post_type', array('post', 'your_post_type', 'page')); 
} 
add_action('pre_get_posts', 'firefog_parse_request_tricksy');