Answers.Body: <p>Im answering my own question and I'll probably go overboard in explaining everything exhaustively, but I sunk too much time into this to just let my understanding disappear into my own forget.</p>
  
  <p>In this particular site, site admins use the custom page template 'page-civiform.php' whenever they want to create a page which will contain a CiviCRM form, inserted via shortcode, and this page template allows them to also insert additional content via a custom field which will display in a column alongside the form.  Looks nice.</p>
  
  <p>End users submit the form, and then CiviCRM automatically generates each subsequent page (thank you page, event registration confirmation page, etc).  </p>
  
  <p>These pages will have the same <strong>body classes</strong> as the page where the shortcode was inserted.  </p>
  
  <p>BUT these Civi-generated pages do NOT use the same <strong>content</strong> as the page with the shortcode. And by content, I <em>think</em> this means everything in between <code>get_header()</code> and <code>get_footer()</code>. Instead, they use the content from another page, and there are three ways to specify which page they will use:</p>
  
  <ol>
  <li><p>If there is no other method utilized to specify which page to use, CiviCRM will use the home page. Again, <strong>content</strong>, not body classes (that was the source of my confusion).</p></li>
  <li><p>In CiviCRM > Administer > System Settings > CMS Database Integration, the WordPress Base Page can be set to a specific URL.  Then that page's content will be used.  </p></li>
  <li><p>It is also possible to specify the page via a filter which would go into functions.php or a plugin.  And here's code for that:</p></li>
  </ol>
  
  <p>add_filter( 'civicrm_basepage_template', 'my_basepage_template' ); </p>
  
  <p>function my_basepage_template( $template ) {</p>
  
  <p>return 'page.php'; //whichever template you want</p>
  
  <p>}</p>
  
  <p>The path of least resistance here is to have ALL of these pages (pages with shortcode inserted as well as any resultant civi-generated pages) have the same template, because then this whole situation wouldn't matter.  But on this site, we want some content in a column next to the shortcode-generated form, so that's why we have a separate page template with a custom field ('page-civiform.php').</p>
  
  <p><a href="https://gist.github.com/susanlangenes/739d401c65749dd67308" rel="nofollow">Here</a> is 'page-civiform.php' so you can see how the custom field is conditionally included or not.  The presence of that conditional statement would actually allow me to set this page as the WordPress Base Page, and it would yield the same result, which in this casse is two columns on page with shortcode, one column (just Civi's content) on auto-generated pages.  </p>
  
  <p>Basically, this all comes down to having different design/layout for pages with shortcodes vs civi-generated pages.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-24T18:12:02.263Z
Answers.Text: Thanks for taking the time to explain this - this very issue has been driving me up the wall.  Another way this problem presents itself is on a CiviCRM form that throws a user error - such as not entering a required field.  In that case the appended parameters seem to "hijack" not only the page's body content, but also any templated sidebars, etc.
Answers.UserDisplayName: Eliot Mason
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-26T21:03:10.227Z
Answers.Text: @susan-langenes  have you assigned this template to the civicrm base page?   I looked at doing this via code at install (defining a page template for the /civicrm basepage) but in the end it was decided that might be too treacherous with all the themes out there.  Christian Wach did the work refactoring base page and he may have some more thoughts
Answers.UserDisplayName: Kevin Cristiano
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-27T15:01:24.730Z
Answers.Text: I think I've ironed out the confusion in https://github.com/christianwach/civicrm-wordpress/tree/CRM-18113
Answers.UserDisplayName: Christian Wach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-27T15:02:54.097Z
Answers.Text: The new behaviour is that Civi leaves the template alone unless it is the site homepage being used as the basepage. This is really the only situation where Civi has to take control, because of the likelihood that the homepage is the list of posts or an incompatible template. See my comments in the code.
Answers.UserDisplayName: Christian Wach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-08T22:46:02.200Z
Answers.Text: @ChristianWach that looks great - very clear and much more understandable!
Answers.UserDisplayName: susan langenes
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-02T23:14:19.980Z
Answers.LastActivityDate: 2016-02-02T23:14:19.980Z
Answers.UserDisplayName: susan langenes
Body: <p>I'm on version 4.6.11 of the CiviCRM plugin for WordPress, WP version 4.4.1. </p>
  
  <p>I expect this has something to do with shortcodes, hijacking, and maybe some other things related that I'm having trouble understanding.  Here's what's happening:</p>
  
  <p>I have created a WP page template called page-civiform.php.  It is intended to be used by site admins to create event registration pages and donate pages, and it has some custom fields and specific styling/branding.  Admins use the main content WYSIWYG editor to paste a shortcode from CiviCRM that creates their event registration form or donate form.  All is well, and these pages look good. </p>
  
  <p>Then, once a user registers or donates, the URL of the very page is appended with a query string, and it appears to be retrieving the default page.php sidebar (which is called in page.php).  BUT, the body classes are not those of page.php.  Instead, the body classes are exactly the same as those of the previous page where the shortcode was pasted - that page which is using page-civiform.php template. That's a problem, because it ends up creating an unprofessional appearance with a wonky layout. </p>
  
  <p>I created a page with slug 'civicrm' and in WordPress Base Page setting, it is set to use that page, which does indeed use page.php as its template. On top of that, per the answer <a href="https://civicrm.stackexchange.com/questions/6570/wordpress-base-page-not-working">here</a>, I put a filter into functions.php file to specify using page.php. None of this appears to have any effect.  Removing that filter and changing the WordPress Base Page (to anything else) also appears to have no effect.</p>
  
  <p>Seems the wires are crossed here.  I did see <a href="https://issues.civicrm.org/jira/browse/CRM-17288" rel="nofollow noreferrer">this issue</a>, discussion of which sounds unpromising.</p>
  
  <p>I need the Civi-generated pages to be style-able <em>differently</em> from the pages where shortcodes are pasted; I can't do that when the selectors are identical. </p>
  
  <p>Could <a href="https://issues.civicrm.org/jira/browse/CRM-16235" rel="nofollow noreferrer">this issue</a> be related? Is there a setting somewhere that I am unaware of?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-18T12:47:44.233Z
Comments.Text: I'm a bit confused. I followed your steps and, for me, all stages of event registration remain on the static page which has the shortcode in it. At all points, the custom 'page-civiform.php' template is applied. Do you (or do you not) want this to be the case?
Comments.UserDisplayName: Christian Wach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-24T02:21:42.877Z
Comments.Text: Hi Christian, thanks for stopping in.  In my site, the template 'page-civiform.php' has a custom field (ACF) and no sidebar.  While the subsequent 'pages' of the registration/donation process do indeed get the body classes for the page-civiform.php file, they don't get that custom field (it's just an image), which is okay, but they problem is that for some reason they're getting a sidebar which is only supposed to be called on the default template.
Comments.UserDisplayName: susan langenes
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-27T15:02:18.037Z
Comments.Text: Hi Susan, could you use a Feature Image instead of ACF? Does 'page-civiform.php' have a call to `get_sidebar()`? If so, how are you conditionally hiding it?
Comments.UserDisplayName: Christian Wach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-28T05:38:34.887Z
Comments.Text: A Featured Image might work; I'll try that. The template 'page-civiform.php' doesn't have a `get_sidebar()` call.  Here is a link to a gist of it: [page-civiform.php](https://gist.github.com/susanlangenes/739d401c65749dd67308).
Comments.UserDisplayName: susan langenes
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-29T09:55:14.537Z
Comments.Text: So I'm not clear what the markup is that appears. Is it the theme's sidebar markup or simply your empty '.left-third'?
Comments.UserDisplayName: Christian Wach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-30T23:27:07.657Z
Comments.Text: It is indeed the theme's sidebar markup. It doesn't get the .left-third. I do have a page with a slug 'civicrm' which is using a template called page-civicrm.php, and it has no `get_sidebar()` either.  So I can't for the life of me figure out where that sidebar is coming from. Here's the site: https://www.mrgfoundation.org/give/
Comments.UserDisplayName: susan langenes
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-30T23:50:42.617Z
Comments.Text: I figured it out!  I'm having a harder time with this mini-Markdown formatting.  :/
Comments.UserDisplayName: susan langenes
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-30T23:59:42.400Z
Comments.Text: I forgot that I had a filter in the functions.php file for civi-generated pages to use page.php.  So I changed that to force page-civicrm.php, and removed that page template's call to `get_sidebar()`.   That was where the sidebar was coming from.  Then, in page-civiform.php, I wrote a conditional statement to add a class ("shortcoded") to the main content area if the "left-third" exists.   page-civiform.php output: https://www.mrgfoundation.org/give/   And here's a civi-generated page: https://www.mrgfoundation.org/give/?page=CiviCRM&q=civicrm/contribute/transact
Comments.UserDisplayName: susan langenes
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-31T00:07:55.293Z
Comments.Text: Here's where the wires were crossed for me:  At all stages, the *body classes* from page-civiform.php are used, but once you're past the first page with the shortcode, and you're onto a civi-generated page, then the content from page-civicrm.php is used, but the body classes from page-civiform.php remain.
Comments.UserDisplayName: susan langenes
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-01T09:20:08.480Z
Comments.Text: Hi Susan, great to hear it's sorted. Perhaps you could copy your solution as an answer to your own question?
Comments.UserDisplayName: Christian Wach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-02T21:24:39.360Z
Comments.Text: Yes, absolutely!
Comments.UserDisplayName: susan langenes
Tags: <wordpress>
Title: Custom Template for WP Base Page not working as expected
ThreadText: # Custom Template for WP Base Page not working as expected
  
  (Asked by: username_0 on 2016-01-15)
  
  I'm on version 4.6.11 of the CiviCRM plugin for WordPress, WP version 4.4.1.
  
  I expect this has something to do with shortcodes, hijacking, and maybe some other things related that I'm having trouble understanding. Here's what's happening:
  
  I have created a WP page template called page-civiform.php. It is intended to be used by site admins to create event registration pages and donate pages, and it has some custom fields and specific styling/branding. Admins use the main content WYSIWYG editor to paste a shortcode from CiviCRM that creates their event registration form or donate form. All is well, and these pages look good.
  
  Then, once a user registers or donates, the URL of the very page is appended with a query string, and it appears to be retrieving the default page.php sidebar (which is called in page.php). BUT, the body classes are not those of page.php. Instead, the body classes are exactly the same as those of the previous page where the shortcode was pasted - that page which is using page-civiform.php template. That's a problem, because it ends up creating an unprofessional appearance with a wonky layout.
  
  I created a page with slug 'civicrm' and in WordPress Base Page setting, it is set to use that page, which does indeed use page.php as its template. On top of that, per the answer [here](https://civicrm.stackexchange.com/questions/6570/wordpress-base-page-not-working), I put a filter into functions.php file to specify using page.php. None of this appears to have any effect. Removing that filter and changing the WordPress Base Page (to anything else) also appears to have no effect.
  
  Seems the wires are crossed here. I did see [this issue](https://issues.civicrm.org/jira/browse/CRM-17288), discussion of which sounds unpromising.
  
  I need the Civi-generated pages to be style-able *differently* from the pages where shortcodes are pasted; I can't do that when the selectors are identical.
  
  Could [this issue](https://issues.civicrm.org/jira/browse/CRM-16235) be related? Is there a setting somewhere that I am unaware of?
  
  **Tags:** wordpress
  
  > **Comments:**
  > **username_1**: I'm a bit confused. I followed your steps and, for me, all stages of event registration remain on the static page which has the shortcode in it. At all points, the custom 'page-civiform.php' template is applied. Do you (or do you not) want this to be the case?  
  > **username_0**: Hi Christian, thanks for stopping in.  In my site, the template 'page-civiform.php' has a custom field (ACF) and no sidebar.  While the subsequent 'pages' of the registration/donation process do indeed get the body classes for the page-civiform.php file, they don't get that custom field (it's just an image), which is okay, but they problem is that for some reason they're getting a sidebar which is only supposed to be called on the default template.  
  > **username_1**: Hi Susan, could you use a Feature Image instead of ACF? Does 'page-civiform.php' have a call to `get_sidebar()`? If so, how are you conditionally hiding it?  
  > **username_0**: A Featured Image might work; I'll try that. The template 'page-civiform.php' doesn't have a `get_sidebar()` call.  Here is a link to a gist of it: [page-civiform.php](https://gist.github.com/susanlangenes/739d401c65749dd67308).  
  > **username_1**: So I'm not clear what the markup is that appears. Is it the theme's sidebar markup or simply your empty '.left-third'?  
  > **username_0**: It is indeed the theme's sidebar markup. It doesn't get the .left-third. I do have a page with a slug 'civicrm' which is using a template called page-civicrm.php, and it has no `get_sidebar()` either.  So I can't for the life of me figure out where that sidebar is coming from. Here's the site: https://www.mrgfoundation.org/give/  
  > **username_0**: I figured it out!  I'm having a harder time with this mini-Markdown formatting.  :/  
  > **username_0**: I forgot that I had a filter in the functions.php file for civi-generated pages to use page.php.  So I changed that to force page-civicrm.php, and removed that page template's call to `get_sidebar()`.   That was where the sidebar was coming from.  Then, in page-civiform.php, I wrote a conditional statement to add a class ("shortcoded") to the main content area if the "left-third" exists.   page-civiform.php output: https://www.mrgfoundation.org/give/   And here's a civi-generated page: https://www.mrgfoundation.org/give/?page=CiviCRM&q=civicrm/contribute/transact  
  > **username_0**: Here's where the wires were crossed for me:  At all stages, the *body classes* from page-civiform.php are used, but once you're past the first page with the shortcode, and you're onto a civi-generated page, then the content from page-civicrm.php is used, but the body classes from page-civiform.php remain.  
  > **username_1**: Hi Susan, great to hear it's sorted. Perhaps you could copy your solution as an answer to your own question?  
  > **username_0**: Yes, absolutely!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-02-02. Score: 1 | Accepted answer
  
  Im answering my own question and I'll probably go overboard in explaining everything exhaustively, but I sunk too much time into this to just let my understanding disappear into my own forget.
  
  In this particular site, site admins use the custom page template 'page-civiform.php' whenever they want to create a page which will contain a CiviCRM form, inserted via shortcode, and this page template allows them to also insert additional content via a custom field which will display in a column alongside the form. Looks nice.
  
  End users submit the form, and then CiviCRM automatically generates each subsequent page (thank you page, event registration confirmation page, etc).
  
  These pages will have the same **body classes** as the page where the shortcode was inserted.
  
  BUT these Civi-generated pages do NOT use the same **content** as the page with the shortcode. And by content, I *think* this means everything in between `get_header()` and `get_footer()`. Instead, they use the content from another page, and there are three ways to specify which page they will use:
  
  1. If there is no other method utilized to specify which page to use, CiviCRM will use the home page. Again, **content**, not body classes (that was the source of my confusion).
  2. In CiviCRM > Administer > System Settings > CMS Database Integration, the WordPress Base Page can be set to a specific URL. Then that page's content will be used.
  3. It is also possible to specify the page via a filter which would go into functions.php or a plugin. And here's code for that:
  
  add\_filter( 'civicrm\_basepage\_template', 'my\_basepage\_template' );
  
  function my\_basepage\_template( $template ) {
  
  return 'page.php'; //whichever template you want
  
  }
  
  The path of least resistance here is to have ALL of these pages (pages with shortcode inserted as well as any resultant civi-generated pages) have the same template, because then this whole situation wouldn't matter. But on this site, we want some content in a column next to the shortcode-generated form, so that's why we have a separate page template with a custom field ('page-civiform.php').
  
  [Here](https://gist.github.com/susanlangenes/739d401c65749dd67308) is 'page-civiform.php' so you can see how the custom field is conditionally included or not. The presence of that conditional statement would actually allow me to set this page as the WordPress Base Page, and it would yield the same result, which in this casse is two columns on page with shortcode, one column (just Civi's content) on auto-generated pages.
  
  Basically, this all comes down to having different design/layout for pages with shortcodes vs civi-generated pages.
  
  > **Comments:**
  > **username_2**: Thanks for taking the time to explain this - this very issue has been driving me up the wall.  Another way this problem presents itself is on a CiviCRM form that throws a user error - such as not entering a required field.  In that case the appended parameters seem to "hijack" not only the page's body content, but also any templated sidebars, etc.  
  > **username_3**: @susan-langenes  have you assigned this template to the civicrm base page?   I looked at doing this via code at install (defining a page template for the /civicrm basepage) but in the end it was decided that might be too treacherous with all the themes out there.  username_1 did the work refactoring base page and he may have some more thoughts  
  > **username_1**: I think I've ironed out the confusion in https://github.com/christianwach/civicrm-wordpress/tree/CRM-18113  
  > **username_1**: The new behaviour is that Civi leaves the template alone unless it is the site homepage being used as the basepage. This is really the only situation where Civi has to take control, because of the likelihood that the homepage is the list of posts or an incompatible template. See my comments in the code.  
  > **username_0**: @ChristianWach that looks great - very clear and much more understandable!  
  
  ---
  
  