Skip to content

Instantly share code, notes, and snippets.

@anointed
Created July 16, 2012 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anointed/3120416 to your computer and use it in GitHub Desktop.
Save anointed/3120416 to your computer and use it in GitHub Desktop.
Filter to apply a div before menu output
Here is what I ended up going with. Not the way I wanted to do it, but hell it works...
<?
function tumble_menu( $args = array() ) {
/* Default arguments */
$defaults = array(
'container' => 'ul',
'menu_class' => 'nav',
'menu_id' => 'main_menu',
'theme_location' => 'main-menu',
'echo' => true,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => 1,
'sort_column' => 'menu_order',
'show_container' => false,
'walker' => '',
);
$defaults = apply_filters( 'tumble_nav_default_args', $defaults);
$args = wp_parse_args( $args, $defaults );
echo '<div class="menu-button">Menu</div>';
$main_menu = wp_nav_menu( $args );
}
<?php
function pippin_sample_html() {
ob_start(); ?>
<ul>
<li>List Item <em>One</em></li>
<li>List <strong>Item</strong> Two</li>
<li>List Item <a href="#">Three</a></li>
</ul>
<?php
return ob_get_clean();
}
function pippin_add_html_wrapper($html, $begin, $end) {
// wrap our original HTML with the new tags
$html = $begin . $html . $end;
return $html;
}
add_filter('pippin_html_wrap', 'pippin_add_html_wrapper', 10, 3);
function pippin_print_html() {
$html = pippin_sample_html();
echo apply_filters('pippin_html_wrap', $html, '<div id="sample_wrapper">hello world</div>', '');
?>
<?php
function tumble_menu( $args = array() ) {
/* Default arguments */
$defaults = array(
'container' => 'ul',
'menu_class' => 'nav',
'menu_id' => 'top_nav',
'theme_location' => 'top-menu',
'echo' => true,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'depth' => 1,
'sort_column' => 'menu_order',
'walker' => ''
);
$defaults = apply_filters( 'tumble_nav_default_args', $defaults);
$args = wp_parse_args( $args, $defaults );
$main_menu = wp_nav_menu( $args );
}
function tumble_add_menu_wrapper($html, $begin, $end) {
// wrap our original HTML with the new tags
$html = $begin . $html . $end;
return $html;
}
add_filter( 'tumble_menu_wrap', 'tumble_add_menu_wrapper', 10, 3 );
function tumble_do_menu_wrapper() {
$html = tumble_menu();
echo apply_filters( 'tumble_menu_wrap', $html, '<div class="menu-button">Menu</div>','' );
}
?>
@pippinsplugins
Copy link

If you end up posting a trac ticket, let me know as I'd like to follow it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment