Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1012276

    Hi Guys,

    I would like to add a button to the Main menu to trigger a ‘button onclick=”goBack()’ event.

    #1012292

    Hey gary04,

    1) Please add a custom css class to your “Home” menu item (Appearance > Menus, click on the arrow on the right to edit the menu item). Maybe you need to activate the css class field in the “Screen options” panel (see https://sevenspark.com/how-to/how-to-add-a-custom-class-to-a-wordpress-menu-item ).

    For my sample code I’ll use the class “home_back_button” (without the quotes).

    2) Then add this code to your child theme functions.php (and replace home_back_button if necessary):

    
    add_action('wp_footer', 'ava_add_back_button_script');
    function ava_add_back_button_script(){
    if(is_home() || is_front_page()) return;
    ?>
    <script>
    jQuery(document).ready(function(){
    	jQuery('.home_back_button').click(function(){
    		parent.history.back();
    		return false;
    	});
    });
    </script>
    <?php
    }
    

    Best regards,
    Peter

    #1012295

    Works perfectly. Thanks Dude!!!

    #1012299

    Hi,

    Great, glad I could help you :)

    Best regards,
    Peter

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.