How to create bootstrap header ACF field with active class menu in wordpress

To create a Bootstrap header with an active class menu using Advanced Custom Fields (ACF) in WordPress, you’ll need to follow several steps. This involves creating custom fields for your menu items, retrieving the values in your WordPress theme, and adding the active class to the current menu item.

$post->ID This is page ID.

<?php if( have_rows('treatments_menu', 'option') ): ?>
    <?php while( have_rows('treatments_menu', 'option') ) : the_row(); ?>
        <li class="nav-item">
            <?php
            $link = get_sub_field('menu_link');
            if( $link ):
                $link_url = $link['url'];
                $link_title = $link['title'];
                $link_target = $link['target'] ? $link['target'] : '_self';
                ?>
                <a <?php if( $post->ID == 258) { echo 'class="nav-link active"'; } else { echo 'class="nav-link"'; } ?> href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>"><?php echo esc_html( $link_title ); ?></a>
            <?php endif; ?>
        </li>
    <?php endwhile; ?>
<?php endif; ?>
Learn Tutorials Point
We Well organized and easy-to-understand Interactive tutorials With lots of examples of how to use Tutorials WordPress, PHP, Bootstrap, Bootstrap 4, HTML, CSS, AJAX, jQuery, Woocommerce, Post, Database, Javascript, Theme, Responsive, Templates.
Comments
  • Hello to all, the contents present at this site are in fact amazing for people
    knowledge, well, keep up the nice work fellows.

  • I am regular visitor, how are you everybody? This paragraph posted at this website is
    actually pleasant.

  • Your style is so unique in comparison to other folks I have read stuff from.
    Many thanks for posting when you’ve got the opportunity,
    Guess I will just bookmark this web site.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact us

Fill in the form below or give us a call and we'll contact you. We endeavour to answer all enquiries within 24 hours on business days.