• Hello,

    I have couple of different types of custom Posts: Events, Courses, News.
    Now my SEO Team is demanding for different Permalink structures for different post types.

    They want the default permalink will be like – /%postname%/
    But for Events they need to be like – /%postname%_POSTYEAR/
    (because event name can be same but if they happens each year)
    But for Courses they need to be like – /%postname%_%post_id%/
    (course name can be same but provider name will be different)
    etc.

    How to do it? with and without any plugin?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    That’s not really a custom permastruct as WP uses the term, it’s really a custom post slug. What you would want to do is modify the default title slug that’s composed after the title is entered. If the POSTYEAR is always the current year, that’s fairly simple to add. Adding the post ID is not so easy because the final assigned ID is not known until the post is actually published.

    Forgetting the lack of ID data for the moment, ideally you would want to modify the slug when it’s created. This is accomplished with an AJAX request. I’m unsure of what code is called when a title slug is needed, but that information exists somewhere, though it may be hard to find. I’ll look deeper if you want to go this route. Remember though that the post ID is not available this way.

    Another possibility is to let the title slug be what it is for editing and alter it after the edit form is submitted. The ‘wp_insert_post_data’ filter can be used for this, the title slug is keyed by ‘post_name’. You can get the post ID through this filter if it’s an update, but not for new posts.

    For new posts I think the only way to incorporate the post ID in the title slug is to hook ‘wp_insert_post’ and re-save the post with the modified title slug.

    I’m not aware of any plugin that would facilitate this, but I tend not to use many plugins, I custom code nearly everything.

    Hi Ayan Debnath,

    Try this plugin for different Permalink structures for different post types.

    https://wordpress.org/plugins/permalinks-customizer/

    Hope it helps you in achieving your goal. 🙂

    Thanks,
    Sami

    Thread Starter ayandebnath

    (@ayandebnath)

    Hi Sami Ahmed Siddiqui,

    I am using this plugin – https://wordpress.org/plugins/custom-post-type-permalinks/

    It’s a great plugin Ayan Thousands of people are using it 🙂

    So, Everything is working fine as your SEO Team wanted to be or still something remaining?

    Regards,
    Sami

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Different Permalink Structure for a Custom Posts’ is closed to new replies.