I am working on my header navigation and I want to underline the menu item for certain conditions.
I would like to add a CSS class if
- the post has the ID 21638, or
- the post has the meta value 'bloom'
The meta value is an ACF relationship field.
<nav class="header-navigation">
<ul class="header-navigation__list">
<li <?php if (is_single(21638)) or (metadata_exists('bloom') echo 'class="current-menu-item"' ?>><a href="<?php echo site_url('/labels/bloom') ?>">Bloom</a></li>
</ul>
I managed to solve the post ID part, but how do I add condition regarding meta value?
or
to||
? and you have a parenthesis in the wrong place. it should beif ( is_single(21638) || (metadata_exists('bloom') )
<?php if ( is_single(21638) or (metadata_exists('bloom') ) ) echo 'class="current-menu-item"' ?>
. VSCode accepts it but I receive an Parse error: syntax error, unexpected 'echo' (T_ECHO)