Switching the menu behavior in Wordpress from opening on hover to opening on click

Running a website called , I have been facing an issue with the sticky hamburger menu located in the top left corner. Currently, the menu opens up when hovered over, which is inconvenient for touchscreen devices as it remains open on smartphones. I have attempted to modify the CSS code responsible for enabling hover effects, but even after disabling certain lines related to the top-menu styling:

#top-menu-selector:hover{color:#BD2A33;-moz-box-shadow: inset 0 0 20px 0 rgba(0,0,0,0.12);-webkit-box-shadow: inset 0 0 20px 0 rgba(0, 0, 0, 12);box-shadow: inset 0 0 20px 0 rgba(0, 0, 0, 0.12);}
    #top-menu ul li:hover ul, 
    #top-menu ul li:hover ul li a,

The menu continues to trigger on hover. Disabling JavaScript also didn't resolve the issue. After analyzing further, I identified that a function within 'sticky.php' file is responsible for generating the menu:

<?php //title attribute gets in the way - remove it
$menu = wp_nav_menu( array( 'theme_location' => 'top-menu', 'container' => false, 'fallback_cb' => 'fallback_pages', 'echo' => false ) );
$menu = preg_replace('/title=\"(.*?)\"/','',$menu);
echo $menu;
?>

I am uncertain about where to modify the CSS or insert the necessary JavaScript code to ensure that the menu opens on click instead of hover. Any guidance on this matter would be greatly appreciated.

UPDATE:

After thorough investigation, I discovered that removing the following element prevents the menu from expanding on hover:

<ul class="sf-js-enabled sf-shadow">

Now, my goal is to find a way to enable menu expansion upon clicking.

UPDATE 2:

To address the issue, I resolved it by incorporating an onclick function into the top menu like so:

<div id="top-menu" onclick="show_hide_menu();">

Subsequently, I added the following script:

<script type="text/javascript">
var clicked = false;
function show_hide_menu()
{
    if(clicked == false){
        document.getElementById("menu-main").style.display = "none";
        clicked = true;
    }else if (clicked == true){
        document.getElementById("menu-main").style.display = "block";
        clicked = false;
    }
}
</script>

This solution effectively eliminates the need to modify the hover implementation and provides an option to close the menu by clicking on it. Moreover, it overrides the hover event, offering a seamless user experience.

Answer №1

<script>
$('#nav-menu .has-children > a').removeAttribute('href');
$('#nav-menu .has-children').click(function(){
    $(this).children('ul').css({'display':'block','visibility':'visible'});
});
</script>

give this a shot and inform me if it does the trick... it's not ideal, but it could work

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using WebP in Sass can be achieved by converting your images to the

I have this code in my SCSS file: .banner{ background-image: url("/images/image.jpg"); } Now, I've switched to a WebP image format. I know how to implement it in HTML like this: <picture> <source type="image/webp" ...

Passing an unpredictable amount of parameters to react router in a dynamic way

Within my React application, users have the ability to create both folders and files. A folder can contain an indefinite number of subfolders within it. Here is an example structure: Folder-1 |_Folder-1-1 |_Folder-1-2 |_Folder-1-2-1 |_Folder- ...

At what point in time does the LoadingFrameComplete event in Awesomium typically happen?

According to the documentation from Awesomium, the event WebView.LoadingFrameComplete is triggered when a frame finishes loading. This description seems somewhat ambiguous. Does this event coincide with the JavaScript load event of the window? Or perhap ...

Issues have arisen with the execution of JavaScript code inside a callback function

When the warnBeforeNew variable is set to false in the JavaScript code below, the file open function works as expected. However, when warnBeforeNew is true, an error occurs stating "Uncaught TypeError: Cannot read property 'root' of undefined". ...

The most efficient method for loading RSS feeds using a combination of Ajax and server-side processing

When deciding on how to load and display a small RSS Feed on your homepage, would you opt for an Ajax (asynchronous) approach or something more server-side oriented (like using node.js)? I am aware of some of the advantages and disadvantages of each metho ...

Designing a fixed bottom footer enclosed within a wrapper that expands from the top header to the bottom footer

I have created the basic structure of my webpage using HTML / CSS. However, I now realize that I need a sticky footer that remains at the bottom of the screen with a fixed position. Additionally, I want the main content area, known as the "wrapper," to str ...

Replace the value of Undefined with an empty string

I have been utilizing exif.js to extract metadata from the images I upload on a content management system (CMS). However, sometimes when an image does not contain any metadata, certain values may show up as "undefined". My goal is to replace these "undefin ...

Ensure that the jQuery Accordion always displays a table within every div

I have implemented an accordion-style menu that toggles the next div area when clicking its parent h3 element. $(document).ready(function() { $('div.accordian-content').find('div').hide(); $('div.accordian-content').f ...

The ability to submit a conversation chat is currently

I encountered an issue when attempting to submit a chat, and I received the error message 'handlebar is not define'. I followed the code tutorial provided in this link: https://codepen.io/drehimself/pen/KdXwxR This is the screenshot of the error ...

Limiting the invocation of the listener method in f:ajax depending on the return value of onevent

I am looking to check if the Onevent javascript function returns true or false. My goal is to restrict the listener method call based on the return value of the Javascript function. However, the code snippet provided is causing a syntax error in Firebug. ...

The slider fails to load correctly

Upon reaching the final slide and returning to the first slide, a small line appears on the left side indicating that the image does not fully cover the slide. Could this be an issue with the JavaScript code? This problem becomes more apparent in full-scr ...

Adding Angular dependencies through Gulp (with the help of Browserify)

Exploring the use of Gulp and Browserify in my new Angular application. Inquiry: How can I effectively include angular dependencies in the app.js file without encountering dependency errors? Even with minimal dependencies, such as using only $stateProvid ...

Preventing page reload using JavaScript function

I am currently encountering an issue with my code. The situation involves pulling items from a JSON database and displaying multiple items on the page. I have implemented a class called showProduct, which triggers when an item is clicked. This class execut ...

Issue in Wordpress: ReferenceError - '$' is not defined

Currently utilizing WordPress and attempting to access the following code snippet. I am encountering an error on the last line }(jQuery)); (function($) { $(function () { // Slideshow 3 $("#slider3").responsiveSlides({ auto: true, pag ...

The function Object.defineProperties() allows for reassigning a property's value after it has been initially

The issue arises in the initial code snippet provided below, specifically when dealing with the object book. Initially, the value of book.year is set to 2013. Even after updating the value by setting book.year = 2015, retrieving the value using book.year s ...

Discover a method to prohibit the use of numbers

Can someone provide me with a Regex pattern to restrict the input in the Name field to only include a mix of text and numbers? I do not want names that consist solely of numbers like 12345678, 3241238215, or 4323438. Rather, it should contain both text and ...

Tips on accessing internal functions within a single module.exports

I'm trying to integrate the getCursor function into the getOffsetCustom function in my code. While I have both functions exported, I can't seem to nest getCursor inside getOffsetCustom successfully. This file is being used for running node witho ...

Retrieve the immediate div sibling that comes after

I have been struggling to create an XPath query that will accurately identify a specific element within a document structure like the one below: <AAA> <div> </div> <div> </div> <div> <div id=' ...

Mastering the art of utilizing sequelize and promises effectively

I'm currently learning how to create apps using expressJS and Sequelize. I could really use some help as I'm more accustomed to sequential programming. My project involves two models: Todo (id, title) and TodoItem (id, content, complete, todoId). ...

The textgeometry element is not appearing in the three.js scene

I've inserted a boxgeometry into the scene with the intention of adding text to indicate the side of the cube. However, I am encountering difficulties in incorporating textgeometry into the scene. This is my code: const loader = new FontLoader(); loa ...