Search code examples
wordpressmenuhref

Change wordpress menu href


I wanna change the href of a specific menu item on all pages. Is this possible? Where should I put the code?

I also added this javascript to the end of a specific page:

<script type="text/javascript">
    document.getElementById("menu-item-100").href="xyz.php"; 
</script>

It didn't work even though when I viewed the page source it showed that the script was placed after the original href of the menu. I don't wanna use custom links.


Solution

  • Try putting this in your footer.php

    <script>
    jQuery(document).ready(function($) {
      $("#menu-item-100").attr("href", new_href);
    });
    </script>
    

    Wordpress a lot of the times needs to have jQuery(document).ready(function($) for no-conflict reasons.