Home › Forums › Calendar Products › Events Calendar PRO › Removing /event/ from single event slug
- This topic has 5 replies, 4 voices, and was last updated 7 years, 6 months ago by Colleen.
-
AuthorPosts
-
September 28, 2016 at 2:53 pm #1170069ColleenParticipant
Hi there,
After searching the forum for ideas on how to remove the /event/ slug from the single event only, I found this code:
/** * Remove the slug from published post permalinks. Only affect our custom post type, though. */ function gp_remove_cpt_slug( $post_link, $post, $leavename ) { if ( 'tribe_events' != $post->post_type || 'publish' != $post->post_status ) { return $post_link; } $post_link = str_replace( '/event/', '/', $post_link ); return $post_link; } add_filter( 'post_type_link', 'gp_remove_cpt_slug', 10, 3 ); /** * Some hackery to have WordPress match postname to any of our public post types * All of our public post types can have /post-name/ as the slug, so they better be unique across all posts * Typically core only accounts for posts and pages where the slug is /post-name/ */ function custom_parse_request_tricksy( $query ) { // Only noop the main query if ( ! $query->is_main_query() ) return; // Only noop our very specific rewrite rule match if ( 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) { return; } // 'name' will be set if post permalinks are just post_name, otherwise the page rule will match if ( ! empty( $query->query['name'] ) ) { $query->set( 'post_type', array( 'post', 'tribe_events', 'page' ) ); } } add_action( 'pre_get_posts', 'custom_parse_request_tricksy' );
However, something breaks along the way…the content area of the events show up, but the export to calendar buttons, as well as the primary meta and the secondary meta areas, won’t display. It’s almost as if a whole other page was setup, especially weird, because I can access the event in its entirety by going to /event/permalink, but /permalink is only “half loaded” (if that makes sense).
I know this is probably outside of the scope of the Pro support, but if you could guide me to some clues as to what is causing this, I’d very much appreciate it. Is it the pre_get_posts call that is somehow interfering? That’s one I’m not great with, so that could certainly be it.
Thanks in advance
September 29, 2016 at 7:26 am #1170359JoshParticipantHey Colleen,
Thanks for reaching out to us!
I am limited in the amount of support that I can provide for a customization such as this. However, you can try removing the second function and filter on “pre_get_posts” there. That function is a bit of a safety net to help with clashing of conflicting post/page/event slugs. You can remove as an initial test here to see if it helps here.
Looking at the first function though, it seems to be a clear and straightforward way for getting what you’re looking for. If the issues you’re describing are solely driven by that function, I fear that the solutions would be a bit of a Whac-A-Mole to get things working.
Thanks!
September 29, 2016 at 8:09 am #1170381ColleenParticipantThanks Josh,
It’s weird, because I thought the first function would do the trick too, but what ends up happening (without the second “pre_get_posts” filter) is that /permalink redirects to /event/permalink, so it goes the other way. Strange.
Thanks for the help; I think I might be out of luck for now, but at least there is a redirect in place. Despite it going the other way, I suppose the good news is that my client’s event pages from their previous site will be routed properly.
Colleen
September 30, 2016 at 8:00 am #1171003JoshParticipantHey Colleen,
Thanks for following up here. I’m sorry I wasn’t able to help get you closer to what you were looking for, however I’m glad you were able to get something that works for you here.
Thanks!
October 22, 2016 at 9:35 am #1181272Support DroidKeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Removing /event/ from single event slug’ is closed to new replies.