function remove_admin_bar() { if (!current_user_can(‘administrator’) && !is_admin()) { show_admin_bar(false); } } add_action(‘after_setup_theme’, ‘remove_admin_bar’);
Kategorie: Snippets
Ändere das Login-Logo
function custom_login_logo() { echo ‘<style type=”text/css”>h1 a { background-image: url(‘.get_stylesheet_directory_uri().’/images/custom-login-logo.png) !important; }</style>’; } add_action(‘login_head’, ‘custom_login_logo’);
Entferne unerwünschte Widgets aus dem Dashboard
function remove_dashboard_widgets() { remove_meta_box(‘dashboard_widget_id’, ‘dashboard’, ‘normal’); } add_action(‘wp_dashboard_setup’, ‘remove_dashboard_widgets’);
Deaktiviere die automatische Aktualisierung von Plugins
add_filter(‘auto_update_plugin’, ‘__return_false’);
Füge benutzerdefinierte Schriftarten hinzu
function add_custom_fonts() { wp_enqueue_style(‘custom-fonts’, ‘https://fonts.googleapis.com/css?family=Font1|Font2’); } add_action(‘wp_enqueue_scripts’, ‘add_custom_fonts’);
Füge benutzerdefinierte Felder zur Mediathek hinzu
function add_custom_media_fields($form_fields, $post) { $form_fields[‘custom_field’] = array( ‘label’ => ‘Benutzerdefiniertes Feld’, ‘input’ => ‘text’, ‘value’ => get_post_meta($post->ID, ‘_custom_field’, true), ); return $form_fields; } add_filter(‘attachment_fields_to_edit’, ‘add_custom_media_fields’, 10, 2); function save_custom_media_fields($post, $attachment) { update_post_meta($post[‘ID’], ‘_custom_field’, $attachment[‘custom_field’]); return $post; } add_filter(‘attachment_fields_to_save’, ‘save_custom_media_fields’, 10, 2);
Füge benutzerdefinierten Code zum Header hinzu
function custom_header_code() { echo ‘<!– Dein Header-Code hier –>’; } add_action(‘wp_head’, ‘custom_header_code’);
Deaktiviere die WordPress-REST-API
function disable_rest_api() { return new WP_Error(‘rest_disabled’, ‘Die REST-API wurde deaktiviert.’, array(‘status’ => 403)); } add_filter(‘rest_authentication_errors’, ‘disable_rest_api’);
Ändere das Standard-Image-Upload-Verzeichnis
function custom_upload_dir($path) { $upload_dir = wp_upload_dir(); $path[‘path’] = $upload_dir[‘basedir’] . ‘/custom’; $path[‘url’] = $upload_dir[‘baseurl’] . ‘/custom’; return $path; } add_filter(‘upload_dir’, ‘custom_upload_dir’);
Entferne die Version von WordPress aus dem Header
function remove_wp_version() { return ”; } add_filter(‘the_generator’, ‘remove_wp_version’);