Hi Guys,
I would like to add a button to the Main menu to trigger a ‘button onclick=”goBack()’ event.
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
Works perfectly. Thanks Dude!!!
Hi,
Great, glad I could help you :)
Best regards,
Peter