-
Notifications
You must be signed in to change notification settings - Fork 0
Filters
The following filters are accessible via add_filter(). Included are sample closures, with comments
Configuration and HTML construction outside of the actual WordPress Menu.
When merging $args and $this->cfg, append (true) or overwrite (false) array values which have a numeric key?
add_filter( 'flexwalker_menu_numeric', function( $bool ) {
// always append
return TRUE;
}, 10, 1 );The merged array of arguments being used by Flexwalker.
add_filter( 'flexwalker_menu_args', function( $array ) {
// change walker container_id argument
$array['walker']['container_id'] = 'mynewid';
return $array;
}, 10, 1 );The template being used by Flexwalker. Note, this needs to be in the 'template' format, see JSON: templates. If it's empty, Flexwalker will return nothing.
add_filter( 'flexwalker_menu_template', function( $array ) {
// change depth
$array['depth'] = 1;
return $array;
}, 10, 1 );Flexwalker by default generates a random ID to assign to the menu.
add_filter( 'flexwalker_menu_id', function( $string ) {
// change to your own value.
return 'myniftyid';
}, 10, 1 );This is structure of the HTML returned, see JSON: templates for more information. There should be a special walker item in this array if you are actually calling a menu.
add_filter( 'flexwalker_navbar_tags', function( $tags_array, $template_id ) {
// be careful here, see JSON: templates
return $tags_array;
}, 10, 2 );Use 'close' instead of 'open' within the filter name to get the same information for the closing tag.
// $key is the numeric key corresponding to the array shown in the previous filter
add_filter( 'flexwalker_navbar_open_tag', function( $array, $key, $template_id ) {
// $array is a tag array as seen in JSON: tags
return $array;
}, 10, 3 );Use 'close' instead of 'open' within the filter name to get the same information for the closing tag.
// $key is the numeric key corresponding to the array shown in the previous filter
add_filter( 'flexwalker_navbar_open_html', function( $string, $key, $template_id ) {
// $array is a tag array as seen in JSON: tags
// $string will include any content configured within the tag array
return $string;
}, 10, 3 );This is the completely rendered HTML string.
add_filter( 'flexwalker_navbar_html', function( $string, $template_id ) {
// this will include the Flexwalker_Walker html output
// within other configured structure
return $string;
}, 10, 2 );The arguments sent to wp_nav_menu.
add_filter( 'flexwalker_get_walker', function( $array ) {
// change menu_class
$array['menu_class'] = 'my-menu-class';
return $array;
}, 10, 1 );Flexwalker looks for a tag with the id of 'menu', and this will be empty otherwise.
add_filter( 'flexwalker_wrapper_tag', function( $string ) {
// should be an un-bracketed tag, like 'div' or 'p'
return $string;
}, 10, 1 );Specifically the sprint string sent as the items_wrap argument
add_filter( 'flexwalker_wrapper', function( $string ) {
return $string;
}, 10, 1 );This is how Flexwalker gets its tag information into the walker class.
add_filter( 'flexwalker_walker_filter', function( $array ) {
// $array:
// [
// 'flextags' => [],
// 'flextemp' => [],
// 'nid' => '',
// ]
return $array;
}, 10, 1 );Filter the array of data which is being made available to flexwalker.js. Note that arbitrarily changing the structure or keys will probably break things.
/*
* $array contains the contents of $this->cfg['display'] as modified by the
* passed arguments when flexwalker( $args ). $this->cfg['display'] is initially
* the contents of display.json
*/
add_filter( 'flexwalker_localize', function( $array ) {
// turn off resize hiding
$array['resizehide']['use'] = false;
return $array;
}, 10, 1 );