Okay
  Public Ticket #2515652
changing the URL
Closed

Comments

  •  16
    wheelsacrossmorocco started the conversation

    Hi, I'm looking to change the - after courses to a /

    In edit, it won't accept. Using category/postname in permalinks custom just gives me a 404. Any thoughts? Thanks

  • [deleted] replied

    Hi Darren,

    So you are trying to make that URL:

    https://creativecamera.online/courses-photography-ideas/

    To:

    https://creativecamera.online/courses/photography-ideas/

    In this case you can only make with custom coding because WordPress doesn't allow adding forward slashes in permalinks.

    Optionally, you can make all portfolio items with prefix /courses in Theme Options > Portfolio Settings > Portfolio Page > URL Rewrite Options:

    medium
    (view large image)

    But then all portfolio items will have /courses prefix. Will that work for you?

  •  16
    wheelsacrossmorocco replied

    Hi, Yes convert to: 
    https://creativecamera.online/courses/photography-ideas/

    "But then all portfolio items will have /courses prefix. Will that work for you?''

    No, that won't work as some will need to be workshops or tutorials.

    What's custom coding?

  • [deleted] replied

    I've added the following code in functions.php of child theme:

    // Custom rewrite URL (The first parameter is how you want the URL to be.)
    add_action( 'init', function() {
        add_rewrite_rule( '^courses/photography-ideas/?', 'index.php?portfolio=courses-photography-ideas', 'top' );
    } );
    
    So now you can access it:

    https://creativecamera.online/courses/photography-ideas/

    Please note that if you change the slug of that portfolio item you have to replace it in index.php?portfolio=your-new-slug


  •  16
    wheelsacrossmorocco replied

    Ok, but it's not changed on the site?

    Also I will need to do the same for workshops and tutorials.

    Can I just change the slug on the snippet area?

    [EDIT]

    The site is going live to clients now so looking to avoid page breaks for a day or so.

  •  16
    wheelsacrossmorocco replied

    Hi, can you give me some clear steps either with a link to a video or page so I can make the changes for courses, tutorials and workshops/

    thanks

  • [deleted] replied

    Hi Darren,

    For custom URL structure like that it requires custom coding, so I am giving you an idea how you can change the appearing URL of that item, so by adding:

    add_filter( 'wp_setup_nav_menu_item', function( $menu_item) {
        if ( $menu_item instanceof WP_Post && strpos( $menu_item->url, 'courses-photography-ideas' ) !== false ) {
            $menu_item->url = home_url( 'courses/photography-ideas/' );
        }
        return $menu_item;
    } );
    

    In the menu will look like:

    https://d.pr/v/TLNtZZ

    So based on this pattern you can replace for other pages. 

    Note that this is custom code, since we do not provide custom work in support I gave you this time to help you out of support scope.

  •  16
    wheelsacrossmorocco replied

    Yes, I understand, much appreciated - the video - shows me where to go. I will have a play around tomorrow but will back up the site beforehand, thanks.

  •  16
    wheelsacrossmorocco replied

    Hi, the URL are not for the top level menu, but instead for the internal pages. Should I remove the 'add filter set-up nav menu item'?