Overwriting Core WordPress Functions with Plugins

Not really, no. You can override built-in PHP functions, but not user-defined functions.

However, all this function does is define a meta box. Why not define your own?

Once you’ve got your own meta box defined and added, you can call remove_meta_box to remove the standard one:

remove_meta_box( 'add-POSTTYPENAME', 'nav-menus', 'side');

The meta box is originally added for each custom post type using a loop. The ID of the meta box is defined as add-{$id} where $id is the name of the post-type. So you can remove this meta box for all post types by doing a similar loop, or just for a specific post type. It’s up to you.

Then just add your custom meta box for the post types you need. Here’s the function that adds the original for reference:

function wp_nav_menu_post_type_meta_boxes() {
      $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' );

      if ( ! $post_types )
          return;

      foreach ( $post_types as $post_type ) {
          $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
          if ( $post_type ) {
              $id = $post_type->name;
              add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type );
          }
      }
}

Leave a Comment