I am using the child theme for customization and now I want to replace the top menu with a custom widget or a file that contains custom content, but the theme does not support hooks, filters and actions, so how do I replace it without modifying core header.php?

Here is how the top menu being called right now:

<?php $main_top = array('theme_location' => 'Top_Menu', 'container' => '', 'menu_class' => 'sf-top-menu', 'menu_id' => 'menu-top', 'fallback_cb' => false);?>

<?php if(!of_get_option('disable_top_menu')==1){?>

<div class="mainmenu"> 
    <?php wp_nav_menu($main_top);?>
    <div class="clearfix"></div>
    <?php }?>
  • The code you give is the definition of an array. It doesn't do anything. – cjbj Aug 29 '16 at 10:17
  • @cjbj I have updated the code – Kevin S Aug 29 '16 at 10:25

You can modify the arguments passed to wp_nav_menu with a filter called wp_nav_menu_args. You can use this filter to add a walker class, which will modify the behaviour of wp_nav_menu.

This approach is kind of hackish, because the walker class will still 'walk' through all the menu items, but you can control them, so decide not to output any item. Here's a nice tutorial on the walker class.

Inside your walker class you can include your custom content. Note that you'll need to add html, as PHP code will not be evaluated anymore.

| improve this answer | |
  • can you please give me an example in my case? I am not very familiar with filters. – Kevin S Aug 30 '16 at 6:25
  • Learning about filters is not the most difficult part in what you are trying to achieve. There are plenty of tutorials online. The walker class is the hard bit. We're not talking a few lines of code here, but some serious programming (as a result of your theme not supporting hooks and your understandable unwillingness to modify header.php). – cjbj Aug 30 '16 at 7:26
  • I am trying to learn as much as I can and I tried to do your way and I spent the last 2 hours trying to figure it out. My IQ is lower then average due to some sickness and under medication most of my life. I hope that someday I will be able to grasps things as other do. I have already posted to the theme author on Themeforest but haven't got any reply yet. – Kevin S Aug 30 '16 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.