fbpx

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;
}

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/ Systems Administration and Computer Science from the Community College of Baltimore County. When he’s not working, Sean can be found playing Super Nintendo or electric guitar.

Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

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/ Systems Administration and Computer Science from the Community College of Baltimore County. When he’s not working, Sean can be found playing Super Nintendo or electric guitar.

Post Details

Categories: