doukangbin9698
2016-02-03 10:05
浏览 116
已采纳

如何在wordpress中更改自定义帖子类型slug

I install edd plugin and add products. When I click on a product for single page or click any edd category the link generated http://site_url/downloads/category/recent-issues/ by plugin. Now I want to change the slug of post type.

Like

http://site_url/downloads/category/recent-issues/

To

http://site_url/issues/category/recent-issues/

I searched from google and found this code.

function add_custom_rewrite_rule() {
    $current_rules = get_option('rewrite_rules');

    if( ($current_rules) ) {
        foreach($current_rules as $key => $val) {
            if(strpos($key, 'download') !== false) {
                add_rewrite_rule(str_ireplace('download', 'issues', $key), $val, 'top');
            } // end if
        } // end foreach

    } // end if/else

    // ...and we flush the rules
    flush_rewrite_rules();

} // end add_custom_rewrite_rule
add_action('init', 'add_custom_rewrite_rule');

But this code not working. "Download" is the post type of edd products.

So how can I change the slug of edd post type.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutang7415 2016-02-03 10:56
    已采纳

    there is just a single line code to achieve what you want.

    define('EDD_SLUG', 'issues');
    

    Remove your above code and paste this one in functions.php.

    For reference read this article.

    打赏 评论

相关推荐 更多相似问题