L
L
ligisayan2017-11-25 18:19:11
User navigation
ligisayan, 2017-11-25 18:19:11

How to add function output to wordpress menu properties?

Hello! There is a menu in wordpress in which I want to include the last item li in the result of displaying the value of the dynamic sidebar<?php dynamic_sidebar( "crypto_currency" ); ?>

<nav id="secondary-navigation" class="main-navigation secondary-navigation" role="navigation">
    <?php if ( has_nav_menu( 'secondary' ) ) {
            wp_nav_menu( array(
            'theme_location' => 'secondary',
            'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>';
                ) );
            } ?>
    <span><?php dynamic_sidebar( "crypto_currency" ); ?></span>
</nav><!-- .secondary-navigation -->

But, I can't include it in a wrapper and make everything appear on one line. In the first case, the ul list occupies the entire line and the span is already displayed on the second line. In the second case, I get a menu error, because. wp_nav_menu properties do not support dynamic php output and ul is not closing the way I would like (error in menu) Help me figure out how to fix this moment
<nav id="secondary-navigation" class="main-navigation secondary-navigation" role="navigation">
    <?php if ( has_nav_menu( 'secondary' ) ) {
        $items_wrap = 
        wp_nav_menu( array(
            'theme_location' => 'secondary',
            'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</li>'+dynamic_sidebar( "crypto_currency" )+'</li></ul>'
        ) );
    } ?>
</nav><!-- .secondary-navigation -->

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2017-11-25
@ligisayan

somehow so

add_filter( 'wp_nav_menu_items', 'wpp_add_menu_item', 10, 2 );
  function wpp_add_menu_item ( $items, $args ) {
    if ($args->theme_location == 'secondary') {
      ob_start();
      dynamic_sidebar( "crypto_currency" );
      $item = ob_get_clean();
      $items .= sprintf('<li>%s</li>',$item);
    }
    return $items;
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question