Showing posts with label anchor. Show all posts
Showing posts with label anchor. Show all posts

Thursday, September 14, 2023

How to add additional class to WordPress navbar anchors

 

//Function In function .php

function add_additional_class_on_a($classes, $item, $args)
{
    if (isset($args->add_a_class)) {
        $classes['class'] = $args->add_a_class;
    }
    return $classes;
}
add_filter('nav_menu_link_attributes', 'add_additional_class_on_a', 1, 3);

//Code for Header.php

 <?php

                $web_menu = wp_nav_menu(array(

                'theme_location' => 'menu-1',

                'menu_id' => 'primary-menu',

                'menu_class' => 'navbar-nav',

                'add_a_class' => 'nav-link', //Here is the class

                 'container' => 'ul',

                'echo' => false

            )

            );

            $web_menu = str_replace('menu-item', 'nav-item', $consult_menu);

                echo $web_menu ;

            ?>

Wednesday, March 29, 2023

jQuery to smoothly scroll page

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>
$(document).ready(function(){
  
  $("a").on('click'function(event) {
     
if (this.hash !== "") {
    
 event.preventDefault();
     
var hash = this.hash;
     
$('html, body').animate({
       
 scrollTop: $(hash).offset().top
      
}, 800function(){
       
window.location.hash = hash;
      
});
   
 }
  
});

});
</script>

1 hour Free Service for WordPress website :)

      1 hour Free Service for WordPress website :)