Support

Home Forums Event Espresso Premium Redirect all espresso post pages to something other than slug

Redirect all espresso post pages to something other than slug

Posted: September 27, 2019 at 7:03 am

Viewing 3 reply threads


Alex

September 27, 2019 at 7:03 am

Our custom course pages are currently setup under slug “/ce-courses/” followed by the page name. When pointing directly at the slug it goes to another custom design page that provides a full listing of the courses we offer. EE is setup under the default “/events” slug and I’d like to get around the need to have basically 2 sets of pages for each course, the EE post AND the custom page. Essentially we are using EE on each of the custom pages through the [ESPRESSO_TICKET_SELECTOR event_id=xxx] shortcode and this works well. It would be nice to be able to use the EE event list page /events/ BUT redirect all the calls within this page to the actual custom event page. So for example:

/ce-courses/course1 – custom page, content, and ticket_selector.
/events/ – standard event list page using all options within EE.
/events/course1 – EE event page which I’d like to keep empty and only use for the ticket selector, datetime options / etc..ie: not have any HTML coding under content area.

I’d like all click through links on all /event pages (and any page that uses the [ESPRESSO_EVENTS] tag to instead of linking to the EE events /events/course1… to instead link to the custom page /ce-courses/course1 that I’ve already designed and customized.

I *kind* of got this to work by accident by using the CPT rewrite filter below and *NOT* refreshing the permalinks. As soon as I go into permalinks and then just touch / save the file this code rewrites the entire slug and changes the category as intended.

add_filter( 'FHEE__EE_Register_CPTs__register_CPT__rewrite', 'my_custom_event_slug', 10, 2 );
function my_custom_event_slug( $slug, $post_type ) {
if ( $post_type == 'espresso_events' ) {
$custom_slug = array( 'slug' => 'ce-courses' );
return $custom_slug;
}
return $slug;
}

Is there a way via filter or otherwise to selectively apply a link rewrite on all event pages to their corresponding /ce-courses pages. This would also fix the link in the emails that go out to registrants that link back to the /events/course1 version of the page.

Why even try and do this to begin with vs. just using EE event as it was intended? I am using visual composer on my custom pages and there is some page or CSS weirdness that is introduced when trying to copy and paste all the raw HTML into the EE event page. Also I would like a custom page to be displayed when users go to /ce-courses/ instead of that linking to the default EE event list page if for instance I changed the entire event slug option under Event List Pages. Any help would be greatly appreciated!


Josh

  • Support Staff

September 27, 2019 at 8:10 am

Hi,

One thing you could do is set up a redirect for /events/ and redirect it to /ce-courses/

This would involve:
1) Make a page with slug ce-courses and place the [ESPRESSO_EVENTS] shortcode on it; all of your custom event pages will be set to use this as their parent page
2) Install the Redirection plugin
3) Add this redirect to the Tools > Redirections page:
Source URL: /events/(.*)
Select Regex (checkbox)
Target URL: /ce-courses/$1


Alex

September 27, 2019 at 1:48 pm

Hi Josh,
This seems to work server side, however when on the new custom page featuring [ESPRESSO_EVENTS] shortcode on it, all the links on this page still point to the original /events/course1 page (when user rolls over it). Similarly in the email templates that go out for registrations the original /events/.* link still persists there as well. Is there a way to do a rewrite before the page is rendered so that it displays properly on all pages.. I guess this would also then negate need for redirect plugin if this could somehow be done filter-side.


Josh

  • Support Staff

October 1, 2019 at 9:39 am

It can be done with a filter, but the links in the messages won’t be affected. Here’s an example of a filter function that you could modify/use/adapt:

function point_event_url_to_related_page( $url, $post ) {
    if ( 'espresso_events' == get_post_type( $post ) && ! is_admin()) {
        if(get_page_by_path('ce-courses/'.$post->post_name)){
            $url = str_replace('events', 'ce-courses', $url);
        }
    }
    return $url;
}
add_filter( 'post_type_link', 'point_event_url_to_related_page', 10, 2 );

Then to change the event URL within the emails you could build a custom shortcode for outputting the custom URL. Here’s a link to the documentation that outlines how to create a custom message template shortcode:

https://eventespresso.com/wiki/messages-system-how-to-add-custom-message-shortcodes/

Viewing 3 reply threads

The support post ‘Redirect all espresso post pages to something other than slug’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso