It's better to address the issue rather than suppress the warning message.
The issue is this line:
if(isset($canonical) && $canonical)
The use of isset($canonical)
is fine, however you're directly using the same variable in the same scope, which is causing the message.
Change it to this:
<?php if( isset( $canonical ) ): ?>
<link rel="canonical" href="<?= $canonical ?>" />
<?php endif; ?>
You don't need the extra && $canonical
assuming that you don't have code that would ever initialize the $canonical
variable to a null or empty state.
Other tips:
1. Use <?php
instead of the <?
"short tags" because of symbol conflicts with XML declarations. I understand by default newer versions of PHP have short-tags disabled. Note that the <?= ?>
shorthand (for echo
) is always permitted.
2. Use the if: endif;
syntax to make page rendering code easier to follow.