Skip to content

Instantly share code, notes, and snippets.

@kasparsd
Created March 31, 2015 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasparsd/b166a22fe1612319d416 to your computer and use it in GitHub Desktop.
Save kasparsd/b166a22fe1612319d416 to your computer and use it in GitHub Desktop.
Prepend parent page title to page list in the menu builder
<?php
add_action( 'admin_head-nav-menus.php', 'enable_menu_page_selector_filter' );
function enable_menu_page_selector_filter() {
// Unfortunately Walker_Nav_Menu_Checklist relies on a filter that
// is used also elsewhere and can't be filtered reliably.
add_filter( 'the_title', 'prepend_page_parent', 10, 2 );
}
function prepend_page_parent( $title, $post_id ) {
$post = get_post( $post_id );
if ( 'page' == $post->post_type && ! empty( $post->post_parent ) ) {
return sprintf(
'%s → %s',
wp_trim_words( get_the_title( $post->post_parent ), 2 ),
$title
);
}
return $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment