• Resolved fabiano1987

    (@fabiano1987)


    Hi, i need to change the permalink for you custom post type

    from “site.com/advert/xxx”
    to “site.com/my_custom_permalink/xxx”

    i already tried by adding this to the functions.php:

    add_action("adverts_post_type", "customize_adverts_post_type");
    function customize_adverts_post_type( $args ) {
       if(!isset($args["rewrite"])) {
          $args["rewrite"] = array();
       }
       
       $args["rewrite"]["slug"] = "my_custom_permalink";
       return $args;
    }

    the permalink changes but when i try to load a page it automatically redirects to the homepage so i cannot load the “single” product page anymore. I also refreshed the permalinks from the WP page but no luck..

    what i have to do?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi, after adding the code to your theme functions.php go to wp-admin / Settings / Permalinks panel and click “Save Changes” button this will reset WP router and should fix the links.

    As an alternative instead of using the code snippet you can try a plugin like https://www.ads-software.com/plugins/custom-post-type-permalinks/

    Thread Starter fabiano1987

    (@fabiano1987)

    wp-admin / Settings / Permalinks panel and click “Save Changes”

    Hi Greg i already did this but no luck

    Plugin Author Greg Winiarski

    (@gwin)

    In this case your custom permalink “my_custom_permalink” might conflict with some page in wp-admin / Pages panel which is already using slug-like “my_custom_permalink” to as a name.

    If this is not the case as well, see if you can customize the permalinks using https://www.ads-software.com/plugins/custom-post-type-permalinks/

    Thread Starter fabiano1987

    (@fabiano1987)

    the plugin doesn’t help neither

    with the plugin i’m able to do this:

    /advert/custom/xxx

    but i’m not able to change /advert/

    Plugin Author Greg Winiarski

    (@gwin)

    Can you paste a link to your site so i can take a look at it?

    Thread Starter fabiano1987

    (@fabiano1987)

    https://wallpapers.ispazio.net

    • This reply was modified 6 years, 8 months ago by fabiano1987.
    Plugin Author Greg Winiarski

    (@gwin)

    Thanks one last question to test this, what slug are you looking to use instead of “advert”?

    Thread Starter fabiano1987

    (@fabiano1987)

    I tried with

    /sfondi/
    /sfondo/
    /wallpaper/
    /wall/

    But every time the same problem. As soon as I change the slug, I see 404 not found pages

    then , when I update the wp permalink page, when I click some links it automatically redirects to the home page again. So I’m unable to see the single posts

    Plugin Author Greg Winiarski

    (@gwin)

    Hmm, sorry i cannot really tell what might be causing this problem.

    A code like the one below should allow to change the permalinks and register proper links in the WP router

    
    add_action("adverts_post_type", "customize_adverts_post_type");
    function customize_adverts_post_type( $args ) {
       if(!isset($args["rewrite"])) {
          $args["rewrite"] = array();
       }
       $args["rewrite"]["slug"] = "wall";
       return $args;
    }
    

    I do not know why this is not working for you, one last suggestion i can offer is to try disabling one by one other plugins you have installed and see when and if the problem goes away, if this will not help you can also try switching a theme for a while. This should at least allow isolating the problem.

    Thread Starter fabiano1987

    (@fabiano1987)

    also no luck disabling plugins.. by the way no problem, i will continue to use advert slug.. the site has already been launched and it’s better to continue like this now

    thank you the same ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to change the permalink from “advert” to something else’ is closed to new replies.