I figured it out myself, but by using several different small things. I’m sorry to ‘steal the credit’, – but I can’t remember all the sources used:
This is the 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);
});
And it it called with this function in 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' );