Change page template?

I was looking for a method to dynamically change the page template loaded by Wordpress based on a url query parameter…. The idea was to use <If> statement to get value of query string then use <Load child_theme file=“template2.php” />

<Note>
  //CHECKS QUERY STRING FOR THE PRESENCE OF URL QUERY EMBED
  //IF EMBEDX = YES SETS PAGE TEMPLATE TO NOHEADERNOFOOTER.
</Note>


  <Let name=embed><Url query=embedx></Url></Let>

<If variable=embed not_exists>
  <Exit />
  
  <Else>
        <Load file="https://lotnova.com/public/wp-content/themes/g5-beyot-child/template_without_header_footer_sidebar.php" />

  </Else>
</If>


But nothing happens… What am I missing?

Hi David,
try using the Template tag (See Theme files section) instead of the Load tag (which doesn’t support PHP templates as far as I’m aware)

Also, I’m noticing that you’re using <Let> to set a variable. The proper syntax is <Set>
One last little syntax issue here, <Else> is not a wrapping tag <Else></Else> , but a self-closing tag <Else />.

<Set name=embed><Url query=embedx></Url></Set>

<If variable=embed not_exists>
  <Exit />
<Else />
  <Template theme=part name=template_without_header_footer_sidebar.php />
</If>

Let me know if that works for you!

1 Like