How to add “onclick” event in wordpress menu

i have created page from wp-admin and i have added that page in to menu. and it’s displaying in my website also..

now my question is i want to call pop() function of javascript something like this onclick=”pop(). i don’t have any idea how to do it.

Read More

i have different 5 menus(pages) but i want to add function only for this menu(page)..

i have searched in google also but didn’t get any idea or help.

can you please help me?

Thanks in advance..

Related posts

Leave a Reply

2 comments

  1. You can check body classess.
    By default, wordpress assignes classes to the body to indetify pages/posts

    So for example page with ID 155 will have body class page-id-155
    Then you can check with jQuery

    if($('body').hasClass('page-id-155')) {
        //do your staff
    }
    
  2. You can trigger Js files only on certain post using the $post variable.

    Here is a sample of how you can implement this in your function.php :

    function myjavascript_in_wp_head($pid){
       if (is_page('myPAge')) {
           echo "<script>alert('hello world');</script>";
       }
    }
    add_action( 'wp_head', 'myjavascript_in_wp_head' );