Skip to content
Advertisement

get_meta_tags – if else [closed]

I have:

$tags = get_meta_tags("https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
<div>
    <h1><?php echo $tags['filter-title'] ?></h1>
<div>

How I can add if else, If the meta tag ‘filter-title’ doesn’t exist and I only want to display the text “Filtering” instead?

Advertisement

Answer

to check for the existence of an array key use array_key_exists( 'keyName', $array ).

Like this:

<h1><?php echo ( array_key_exists( 'filter-title', $tags ) ) ? $tags['filter-title'] : 'no filter title found'); ?></h1>

You can substitute whatever you like in place of ‘no filter title found’.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement