0

I have a function that applies a query_var to all links in a page if the query_var exists for the current page.

So if I change

https://liquidchurch.com/messages/

to

https://liquidchurch.com/messages/messages-app-view/

then all the links on the page are updated to look something like this:

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

The problem is with the pagination at the bottom of the page. If you look at the /messages page while messages-app-view is appended you'll see that the permalink to the next page looks like:

https://liquidchurch.com/messages/messages-app-view/page/2/

Problem is that this will return a 404. Ideally I'd like for the URL to be:

https://liquidchurch.com/messages/page/2/messages-app-view/

Alternatively, I suppose a regex would work that checks if /page/x/ is listed after messages-app-view.

Thoughts on how I should accomplish this? Thanks!

1
  • Is "messages-app-view" necessary in the url of your requests? If you're using it to toggle the display of a component or the layout/view mode of the pages, you may want to consider using HTML localStorage (similar to a cookie). Commented Jan 26, 2018 at 6:01

1 Answer 1

0

I ended up going with the regex. In my case that looks like:

 add_rewrite_rule('^messages/messages-app-view/page/?([0-9]{1,})/?$', 
'index.php?pagename=messages&messages-app-view&paged=$matches[1]', 'top');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.