I would like to change the URLs of the single event pages created by the Events Calendar WordPress plugin but only for a specific category. The default URL is 'http://www.example.com/events/post name' and I want to change it to 'http://www.example.com/webinars/post name' but only if the event has a category of webinar.

I created a function for changing the permalink:

add_filter( 'post_link', 'change_webinar_links', 10, 3 );
function change_webinar_links($permalink, $post) {
    if(get_post_type() == 'tribe_events' && has_category('webinar', $post->ID) ) {
        $permalink = trailingslashit( home_url('/webinars/' . $post->post_name  ) );
    }
    return $permalink;
}

I am stuck on creating a rewrite function. I couldn’t find an example that applies to my situation.

I have some of the structure but I don’t know what the regex syntax should be:

add_action('generate_rewrite_rules', 'webinar_link_rewrite');
function webinar_link_rewrite( $wp_rewrite, $post ) {
    if ( has_category('webinar', $post->ID) ) ) {
    $new_rules['regex here'] = ' ';
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    return $wp_rewrite;
    }
}

Could anyone help me with the rewrite rule?

Read more here: Change Events Calendar URL for specific category in WordPress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: