Forum
Use conditionals for page information within a layout?
I have a global header that I use on all of the pages of my site. Page variables are used to display the titles and description metadata for each page.
However, we've decided that some pages will not have a page description. Is there an easy way to use conditional within a layout template so that the empty meta description tag is not shown? I'd prefer for there to be no meta tag instead of a tag that is empty.
Here is my code below:
<title><?php perch_pages_title(); ?> | Small Wonders Doula</title>
<meta name="description=" content="<?php perch_page_attribute('description'); ?>">
And take a look at this post from yesterday - https://forum.grabaperch.com/forum/07-24-2014-seo-tips-for-perch-websites
Graham Street, thanks for the assist. I tried your code above several times. For some reason this isn't working, though. It seems like it's processing the conditional as "false" in all cases because the description isn't showing on any page, even the ones that do have a description written for them.
Is your code on the page or in a template? The <perch:if> only works in a template.
That's because there is PHP in a template on that example
My code is in a template (i.e. Perch > templates > layouts > global.ducument_header.php).
I bring it into each page on the site with:
Code for the global.document_header.php layout template is as follows:
As Dexter says, you have PHP in the template and I'm fairly sure you can't do that.
I would tackle it by having your global.header containing everything but the Title & Meta Description then on each page have
Then use the methods discussed by Rachel & Graham yesterday: https://forum.grabaperch.com/forum/07-24-2014-seo-tips-for-perch-websites
I would do this:
Drew, your solution worked flawlessly (as usual). Thanks again mate.