Skip to content

Instantly share code, notes, and snippets.

@Lindstromer
Last active September 21, 2018 19:15
Show Gist options
  • Select an option

  • Save Lindstromer/2c9de8cba32a66ce64cc8efcec3030ee to your computer and use it in GitHub Desktop.

Select an option

Save Lindstromer/2c9de8cba32a66ce64cc8efcec3030ee to your computer and use it in GitHub Desktop.
Add filter support for array in function
function mg_add_nav_item( $navs ) {
$new_nav_items = [
'navitem',
'navitem2',
'navitem3',
];
$navs = array_merge( $new_nav_items, $navs );
return $navs;
}
add_filter('mg_filter_nav', 'mg_add_nav_item');
function render_nav() {
$navs = ['dinarray' => 'här'];
if ( has_filter( 'mg_filter_nav' ) ) {
$navs = apply_filters('mg_filter_nav', $navs);
}
foreach ( $navs as $key => $nav ) {
echo $nav;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment