mardi 28 février 2017

how to set php variable to another variable when first one is empty then echo

I am trying to create a title from page variables using this.

<?php if $page_title = $page_title ?: $page_name'  - Blah.com'; { ?>
<?php } else { ?>
<?php echo $page_title . " - Blah.com" ; ?>
<?php } ?>

When added to page, all I get is a blank page once I open it in a browser. Not sure if I am doing this right.

I want it to use the page_title variable and some text after it but if page_title is empty I want it to use the page_name instead. Can this be done with shorter code?

Thanks for any help

Aucun commentaire:

Enregistrer un commentaire