custom field – Add CSS class to posts with certain meta key


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

  • when 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> <a href="<?php echo site_url('/labels/bloom') ?>">Bloom</a></li>

I have tried the following but it won’t work

<li <?php if (metadata_exists('bloom') or ($postID(21638))) echo 'class="current-menu-item"' ?>><a href="<?php echo site_url('/labels/bloom') ?>">Bloom</a></li>

Any idea what needs to be fixed?

Charalambos 1 month 2022-12-22T17:28:29-05:00 0 Answers 0 views 0

Leave an answer