Adding custom URL rewrite rule for custom post type slug

Question

I have a theme which defined custom post types. This post type is having a listing page and a single item page for every item. The problem is I can’t change the slug for the custom post type and for the items, I don’t know where and how… So I was thinking maybe I could rewrite these URLs with WP_Rewrite.

So what I want to achieve is change:
xy.com/listing/ to xy.com/mynewname/
and all the xy.com/listing/listing-item/ to xy.com/mynewname/listing-item/

I tried to add this to my functions.php:

function listing_url_rewrite() { 
    add_rewrite_rule(
        "mynewname",
        "listing",
        "top");
}

add_action( 'init', 'listing_url_rewrite' );

But nothing changed actually. So my question is, is it even possible with this rewrite_rule? If yes, what did I wrong? 🙂

Thank you very much!

0
VORiAND 4 months 0 Answers 17 views 0

Leave an answer