我自己想出来的,但用了几个不同的小东西。很抱歉“窃取信用”,但我记不清使用的所有来源:
这是JavaScript:
jQuery(document).ready(function() {
function GetURLParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split(\'&\');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split(\'=\');
if (sParameterName[0] == sParam) {
return sParameterName[1];
} // Endif
} // Endfor
} // Endfor
var just_the_category_ID = GetURLParameter(\'category\'); // Get the category-parameter from the URL
jQuery(\'#in-category-\' + just_the_category_ID ).prop(\'checked\', true);
});
它在
functions.php
:
function custom_enqueue_admin_scripts( ) {
global $page_category_mapping;
$screen = get_current_screen(); // Which page we\'re on
if ( in_array( $screen->id, array( \'page\' ) ) && $screen->action == \'add\' ) {
wp_enqueue_script( \'mark-default-category\', get_stylesheet_directory_uri() . \'/assets/js/THE-LOCATION-OF-THE-JS-FROM-ABOV.js\', array( \'jquery\' ) );
}
}
add_action( \'admin_footer\', \'mss_enqueue_admin_scripts\' );