• Resolved Koesterandersen

    (@koesterandersen)


    Hi weblizar_support

    Sorry but I have put almost the same below question into a resolved question.

    I am about to create pages with parents in order to get a dropdown menu, where I want to be able to click on the parent menu and go to the page itself, separate from the sub menu pages.

    Now I have this question.
    Shall I just overwrite the menu.js file in the parent theme or should I put the menu.js file into a child theme.

    Thanks in beforehand

Viewing 10 replies - 1 through 10 (of 10 total)
  • First you should never replace files in the parent theme the file you used to override it will get replaced if the theme is updated.

    If you are going to place the menu.js in your child theme you will need to place it in your child theme and enqueue it in your functions.php file.

    Thread Starter Koesterandersen

    (@koesterandersen)

    Thank you mrtom414.

    That gave me an answer of my question, but it also created a new question.

    In what way do enqueue the menu.js file. In other words; what do I write in the functions.php file.

    Hi,

    Create a “menu.js” and “functions.php” file into your “Child-Theme” directory.

    Now open “functions.php” file into any text editor.

    Now enqueue the “menu.js” file into “functions.php” file.

    Save the changes.

    Thanks

    Thread Starter Koesterandersen

    (@koesterandersen)

    Hi

    I have already a functions.php file in my child theme, where I have managed to enqueue the css with the following code:

    <?php

    add_action( ‘wp_enqueue_scripts’, ‘enqueue_parent_theme_style’ );
    function enqueue_parent_theme_style() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri().’/style.css’ );
    }

    Now – what I want, is some similar code. Though it should regard the menu.js file. I simply do not know what to write.

    (I have found the code above somewhere at the net and copied into my functions.php – and now I just want to copy and paste some other code, that will enqueue the menu.js file)

    Thanks

    You can add the code in the function enqueue_parernt_theme_style.

    You just need to add the following code

    wp_enqueue_script("MyMenu","get_template_directory_uri()" . "/menu.js");

    note if this script is dependent on another script you will need to add it to the enqueue statement. For Example if your script is depent on jQuery you would use the following statement.

    wp_enqueue_script("MyMenu","get_template_directory_uri()" . "/menu.js" , "jQuery");

    here is the link for the codex

    https://codex.ww.wp.xz.cn/Function_Reference/wp_enqueue_script

    Hi,

    Did the above solution work for you.

    Thanks

    Thread Starter Koesterandersen

    (@koesterandersen)

    Hi

    I cannot get it to work properly. I have tried to put in the above code in different ways – with and without jQuery.

    I might have made an error with my functions.php file, which content the below code:

    <?php

    add_action( ‘wp_enqueue_scripts’, ‘enqueue_parent_theme_style’ );
    function enqueue_parent_theme_style() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri().’/style.css’ );
    wp_enqueue_script(“MyMenu”,”get_template_directory_uri()” . “/menu.js”);
    }

    I am trying to get it work on this website: http://www.tiptoptilbud.dk/

    I am just testing. If you try to click on TESTING 22 and GALLERI in the menu, you will see, that nothing happens.

    sorry remove the quotes from around the get_template_directory_uri(). I’m totally brain dead.

    wp_enqueue_script("MyMenu",get_template_directory_uri() . "/menu.js");

    if your using chrome you can see your scripts by right clicking and selecting the option inspect element than selecting the resource tab >> Frames >> your website name >> Scripts

    Thread Starter Koesterandersen

    (@koesterandersen)

    Hi mrtom414

    I do not think there is anything wrong with your brain 🙂

    Either it must be me – or the system. The fact is, that I cannot get it to work. I have refined and refined the code in the functions.php file, and uploaded the file after every little alteration, but nothing works.

    Here is the last tried code:

    <?php

    add_action( ‘wp_enqueue_scripts’, ‘enqueue_parent_theme_style’ );
    function enqueue_parent_theme_style() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri().’/style.css’ );
    wp_enqueue_script(‘MyMenu’, get_template_directory_uri(). ‘/menu.js’ , ‘jQuery’);
    }

    When I find the scripts as you described, I can see that the menu.js script do not get loaded.

    Do you know if there is a plugin, that can handle the problem. This way here is too much timespending and frustrating for me – and I just think that I will find another theme. Actually I am a bit surprised that the dropdown menu do not function right away without these hacks.
    I know that if I had some more knowledge about programming, it would be no problem, but right now I am quite frustrated.

    If you still are able to help me, it would be very nice and I would definitely be very happy.

    Thanks

    Thread Starter Koesterandersen

    (@koesterandersen)

    Though I have not managed to get it to work, I will now mark this question as solved.

    I have had a direct correspondance with Weblizar, and it is their decision to make dropdown menus the way it is i this theme. So either I will use the theme as it is, or maybe find another one that suits my wishes.

    Thanks for the help to mrtom414

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Drop down menu’ is closed to new replies.