Created
January 31, 2025 21:50
-
-
Save chikaibeneme/cae29be4c5c7d314858640f81685e577 to your computer and use it in GitHub Desktop.
replace_organizer_slug_in_urls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Force organizer post type slug to "ponent" | |
| function modify_organizer_type_properties( $properties ) { | |
| $properties['rewrite'] = array( | |
| 'slug' => 'ponent', | |
| 'with_front' => false, // Optional: depends on your permalink settings | |
| ); | |
| return $properties; | |
| } | |
| add_filter( 'tribe_events_register_organizer_type_args', 'modify_organizer_type_properties' ); | |
| // Force rewrite rules to flush on plugin activation | |
| function custom_events_calendar_rewrite_rules() { | |
| flush_rewrite_rules(); | |
| update_option( 'tribe_events_organizer_slug', 'ponent' ); | |
| } | |
| register_activation_hook( FILE, 'custom_events_calendar_rewrite_rules' ); | |
| register_deactivation_hook( FILE, 'flush_rewrite_rules' ); | |
| // Replace all "/organitzador/" slugs in URLs dynamically | |
| function replace_organizer_slug_in_urls( $template_vars ) { | |
| if ( isset( $template_vars['prev_url'] ) ) { | |
| $template_vars['prev_url'] = str_replace( '/organizer/', '/ponent/', $template_vars['prev_url'] ); | |
| } | |
| if ( isset( $template_vars['next_url'] ) ) { | |
| $template_vars['next_url'] = str_replace( '/organizer/', '/ponent/', $template_vars['next_url'] ); | |
| } | |
| return $template_vars; | |
| } | |
| add_filter( 'tribe_events_views_v2_view_organizer_template_vars', 'replace_organizer_slug_in_urls', 20 ); | |
| // Debug rewrite rules to ensure custom slug is applied | |
| add_action( 'init', function () { | |
| error_log( 'Current Rewrite Rules: ' . print_r( $GLOBALS['wp_rewrite']->rules, true ) ); | |
| error_log( 'Organizer Slug Option: ' . get_option( 'tribe_events_organizer_slug' ) ); | |
| }, 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment