i made this

add_filter('wp_dropdown_cats', 'allow_empty_default_category', 10, 2);
function allow_empty_default_category($output, $parsed_args) {
	var $empty_value = "";
	var $empty_label = "-- NO DEFAULT --";
	if ($parsed_args['name'] == "default_category") {
		$output = str_replace("</select>", "<option value='{$empty_value}'>{$empty_label}</option></select>", $output);
	}
	return $output;
}

arty updated it to this after critical error for using vars and not selecting no default option properly:

add_filter('wp_dropdown_cats', 'allow_empty_default_category', 10, 2);
function allow_empty_default_category($output, $parsed_args) {
	$empty_value = "0";
	$empty_label = "-- NO DEFAULT CATEGORY --";
	if ($parsed_args['name'] == "default_category") {
		$selected = ($parsed_args['selected'] == 0) ? " selected" : "";
		$output = str_replace("</select>", "<option value='{$empty_value}'{$selected}>{$empty_label}</option></select>", $output);
	}
	return $output;
}
norgan

Sean Kellner

Web Applications Engineer
Sean’s strong attention to detail and his passion for coding has made him a huge asset to not only the Foxtrot team, but to any team, including yours. He holds degrees in IT and Computer Science from the Community College of Baltimore County and University of Maryland Global Campus. When he’s not working, Sean can be found playing Super Nintendo or electric guitar.
norgan

Sean Kellner

Web Applications Engineer
Sean’s strong attention to detail and his passion for coding has made him a huge asset to not only the Foxtrot team, but to any team, including yours. He holds degrees in IT and Computer Science from the Community College of Baltimore County and University of Maryland Global Campus. When he’s not working, Sean can be found playing Super Nintendo or electric guitar.

Post Details

Categories: