How to change menu items to sentence case in WordPress

// Update menu items to sentence case
add_action('wp_loaded', 'fl_update_menu_items_case');
function fl_update_menu_items_case() {

  // Get all of the menu item posts
	$all_posts = get_posts([
		'posts_per_page' => -1,
		'post_type' => 'nav_menu_item',
	]);

  // Loop each one setting the title case
	foreach ( $all_posts as $single ) {
		wp_update_post([
			'ID' => $single->ID,
			'post_title' => ucfirst( strtolower( $single->post_title ) ),
    ]);
	}

}

Leave a Comment

Your email address will not be published. Required fields are marked *