0

Okay, so here's what I'm trying to do but having a hell of a time figuring out.

I've got a website that uses the MemberPress plugin. All of those pages by default use the standard default template for each of their dynamically generated pages (i.e. thank you page, checkout page, account page, etc.). Furthermore, these pages are dynamically generated and can not be edited from the admin section to use whatever template you want.

So, all of the pages I am trying to change the template for have one thing in common, they all have a URL that has /register/ in it (i.e. www.mywebsite.com/register/page-name-here/.

Now I checked through all of the WordPress function references at the bottom of the page here... http://codex.wordpress.org/Function_Reference/is_page

I don't see anything I can use to determine if a page URL has /register/ in it but I would like to have some sort of code that I could put within my page.php default template that those pages use. The code would simply say something like...

if URL contains /register/ DO NOT include sidebar. Else include sidebar.

So in other words, the register pages would not include the sidebar and any other pages would include the sidebar. Make sense?

  • the correct way to do this would likely be via a template filter and an inspection of the queried object or query variables, but since it's a paid plugin we don't have access to to verify this, it's probably a question best asked of the plugin's developers. – Milo Jun 16 '14 at 21:26
  • I went ahead and emailed the developers in hopes that they'll give me a solution. It seems like an easy thing to do in my head, I just can't figure out the correct way to do it. – DigitalSky Jun 16 '14 at 21:41
0

Provided not showing the sidebar is the only difference you really want between the way pages are displayed, you can load the sidebar conditionally with something like this in your page.php (or whatever file your theme is using to load the page):

<?php
  if ( strpos($_SERVER['REQUEST_URI'],'/register') == false ) { // if requested uri DOESN'T contain '/register' load the sidebar.
    get_sidebar();
  }
?>

That said, if you need farther reaching changes to the template for those pages, you'd be much better off making a new page template for those pages. Once you have a custom page template in place, you'll be able to choose that template on the page edit for any page on the site. Instructions for custom page templates are in the codex.

  • Thank you! This works for what I am after so I would say it answers my question. However, with the pages I am talking about they are dynamically generated pages so you can't just choose a page template from the WordPress backend because of the fact that they are dynamic. Trust me, I wish it were that easy! – DigitalSky Jun 16 '14 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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