This is a followup to my question, “How can I have two different urls for the same page that load two different templates?”

Assuming I implement Milo’s answer (registering a new rewrite endpoint, load a different template if endpoint is present), how can I then have links within the page rewritten on the fly to include the endpoint (e.g. app-view).

The page the initial endpoint would be added to is:
https://liquidchurch.com/messages/

Based on Milo’s instructions using the rewrite endpoint and page template filter, the url I’d pass from the mobile app would be:
https://liquidchurch.com/messages/app-view/

Now on this page say I click on one of the series, e.g.:

https://liquidchurch.com/sermon-series/divine-direction/

Problem is this will load with the regular template, not the template created particularly for the mobile view. So somehow I have to pass on to this page that it should be displayed in app-view. So the actual URL the individual should be redirected to would be:

https://liquidchurch.com/sermon-series/divine-direction/app-view/

In what way could one accomplish this? Thanks!

1 Answer
1

You can use the page_link filter with the same logic as the page_template filter in the other answer. If the endpoint query var is set, then any link to a page gets the app-view/ appended:

function wpd_page_link( $link, $post_id ){
    global $wp_query;
    if( isset( $wp_query->query_vars['app-view'] ) ){
        return $link . 'app-view/';
    }
    return $link;
}
add_filter( 'page_link', 'wpd_page_link', 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *