I have an H2 and a form at the top of my page, it is present on ever page and is in the Theme template, in header.php, but I need the content to change on 2 specific pages. The current code is this:
<h2 id="formhead">Buy, Hire or Enquire</h2>
<?php echo do_shortcode( '[gravityform id="1" name="Contact Form" title="false" description="false"]' ); ?>
I tried changing it to an if, elseif, else statement:
<?php
if (is_page('54')) {
<h2 id="formhead">Hire or Enquire</h2>
echo do_shortcode( '[gravityform id="3" name="Contact Form" title="false" description="false"]' );
} elseif (is_page('52')) {
<h2 id="formhead">Buy or Enquire</h2>
echo do_shortcode( '[gravityform id="2" name="Contact Form" title="false" description="false"]' );
} else {
<h2 id="formhead">Buy, Hire or Enquire</h2>
echo do_shortcode( '[gravityform id="1" name="Contact Form" title="false" description="false"]' );
}
?>
This however, breaks the site completely and nothing loads. I have no real php experiance(I'm sure there is just a very basic error in the code), only what I've figured out by trial and error, but since this is going on a live site, I can't afford to constantly break the site.
Thanks in advance
Willem
You have to open and close the php tags:
<?php
if (is_page('54')) { ?>
<h2 id="formhead">Hire or Enquire</h2>
<?php echo do_shortcode( '[gravityform id="3" name="Contact Form" title="false" description="false"]' );
} elseif (is_page('52')) { ?>
<h2 id="formhead">Buy or Enquire</h2>
<?php echo do_shortcode( '[gravityform id="2" name="Contact Form" title="false" description="false"]' );
} else { ?>
<h2 id="formhead">Buy, Hire or Enquire</h2> <?php
echo do_shortcode( '[gravityform id="1" name="Contact Form" title="false" description="false"]' );
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With