• Dear out there… ??

    Looks like register_nav_menus isn’t working within a function i wrote to dynamically create dynamic Bootstrapmenus on the theme.

    function navbar($scrolling, $colorclass, $menuname) {
    register_nav_menus( array( $menuname => $menuname) );
    ...

    Is there a proper way to register menu positions via function() in functions.php?

    I noticed that it is necessary to have a register_nav_menus outside the function() to display the Menus Item in BAckend too…

    Would be great to get an answer, just want to create some dynamic menu-functionality.

    Thank you!
    Chris

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Theoretiker

    (@theoretiker)

    No answer is a bit less.

    My Problem is understandable?

    Thread Starter Theoretiker

    (@theoretiker)

    ok, i realized that i have to register menues another time than by rendering the HTML Page…
    so i did a workaround which registers my navbar() placeholder functions in header.php by init-hook.

    Maybe a person which has experience would please have a look at.

    I am not shure if i will go into trouble with this… actually it works.

    function manually_register_available_menupositions() {
    
    $headerfile=fopen(get_template_directory().'/header.php','r');
    
    $content=stream_get_contents($headerfile);
    $find = "(navbar\(.*?\))";
    preg_match_all($find, $content, $matches);
    for ($i = 0; $i <= count($matches[0]); $i++) {
    
    $menuname=substr($matches[0][$i],strrpos($matches[0][$i],',')+2,-2);
    register_nav_menu($menuname, $menuname );
    }
    
    }

    Thank you!
    Chris

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Possible? register_nav_menus wthin a function() in functions.php ?’ is closed to new replies.