Skip to content

Instantly share code, notes, and snippets.

@iansvo
Last active April 26, 2018 20:05
Show Gist options
  • Select an option

  • Save iansvo/f8762bea80144c1965f48f39ced4b782 to your computer and use it in GitHub Desktop.

Select an option

Save iansvo/f8762bea80144c1965f48f39ced4b782 to your computer and use it in GitHub Desktop.
Filter menu items and replace their default output with custom WYSIWYG content
<?php
function add_content_to_sub_menu($item_output, $item, $depth, $args) {
// Checks theme location (remove to apply to any menu)
if( $args->theme_location == 'primary' ) {
// Get Content from ACF Field
$content = get_field('content', $item);
// If there is content, replace the link's regular output
if( $content ) {
$item_output = $content;
}
}
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'add_content_to_sub_menu', 20, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment