Skip to content

Instantly share code, notes, and snippets.

View WordPress-Handbuch's full-sized avatar

WordPress-Handbuch WordPress-Handbuch

View GitHub Profile
@WordPress-Handbuch
WordPress-Handbuch / listing-18-11.php
Last active April 11, 2019 07:02
Exchange the WordPress backend dashboard logo in the top left corner (should be 20px by 20px) through functions.php action hook
function wh_wordpress_backend_custom_logo() {
echo '
<style type="text/css">
#wpadminbar #wp-admin-bar-wp-logo > .ab-item .ab-icon:before {
background-image: url(' . get_bloginfo( 'stylesheet_directory' ) . '/images/custom-logo.png) !important;
background-size: 20px 20px;
background-position: 0 0;
color:rgba(0, 0, 0, 0);
}
#wpadminbar #wp-admin-bar-wp-logo.hover > .ab-item .ab-icon {
@WordPress-Handbuch
WordPress-Handbuch / listing-18-10.php
Last active April 11, 2019 06:20
Change detailled WordPress login error messages to a generic text for security reasons
function wh_hide_login_errors(){
return 'No.';
}
add_filter( 'login_errors', 'wh_hide_login_errors' );
@WordPress-Handbuch
WordPress-Handbuch / listing-18-9.php
Last active April 11, 2019 06:16
Add a header text to the WordPress login page
function wh_add_login_message( $message ) {
return $message . '<h2>Sprich Freund und tritt ein.</h2>';
}
add_filter( 'login_message', 'wh_add_login_message' );
@WordPress-Handbuch
WordPress-Handbuch / listing-18-8.php
Last active April 11, 2019 06:10
Change the WordPress login page logo to any other image
function wh_custom_login_logocss() {
echo '<style type="text/css">
.login h1 a { background-image: url(/pfadunddateinamedeslogos.png); background-size: contain; width:315px; }
</style>';
}
add_action( 'login_head', 'wh_custom_login_logocss' );
@WordPress-Handbuch
WordPress-Handbuch / listing-18-7.php
Last active April 11, 2019 06:01
Add more mimetypes for WordPress' upload functionality
function wh_add_various_mime_types( $mime_types ) {
$mime_types['midi'] = 'audio/midi';
$mime_types['psd'] = 'image/vnd.adobe.photoshop';
return $mime_types;
}
add_filter( 'upload_mimes', 'wh_add_various_mime_types', 1, 1 );
@WordPress-Handbuch
WordPress-Handbuch / listing-18-6.php
Last active April 10, 2019 08:00
Change WordPress excerpt length through the hook excerpt_lengt
function wh_set_excerpt_length( $length ) {
return 150;
}
add_filter( 'excerpt_length', 'wh_set_excerpt_length' );
@WordPress-Handbuch
WordPress-Handbuch / listing-18-5.php
Last active April 10, 2019 13:16
Change WordPress' "Read more" link text after the excerpt using the hook the_content_more_link
function wh_change_more_link() {
return '<a class="more-link" href="' . get_permalink() . '">Hier weiterlesen...</a>';
}
add_filter( 'the_content_more_link', 'wh_change_more_link' );
@WordPress-Handbuch
WordPress-Handbuch / listing-18-4.php
Last active May 6, 2021 23:42
Parsing all WordPress post and page text, link all @ and # words to Instgram tags and profiles
function wh_add_social_links( $content ) {
$content = preg_replace( '/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', "$1<a href=\"https://www.instagram.com/$2/\" target=\"_blank\">@$2</a>", $content );
$content = preg_replace( '/([^a-zA-Z0-9-_&])#([0-9a-zA-Z_]+)/', "$1<a href=\"https://www.instagram.com/explore/tags/$2/\" target=\"_blank\">#$2</a>", $content );
return $content;
}
add_filter( 'the_content', 'wh_add_social_links' );
add_filter( 'comment_text', 'wh_add_social_links' );
@WordPress-Handbuch
WordPress-Handbuch / listing-18-3.php
Last active April 10, 2019 12:38
Adding a simple shortcode for a new HTML bold italics tag through WordPress' hook mechanism
function wh_shortcode_boldanditalics( $attributes, $content ) {
// Hier kann beliebiger PHP-Code ausgeführt werden
return '<b><i>' . $content . '</i></b>';
}
add_shortcode( 'fettkursiv', 'wh_shortcode_boldanditalics' );
@WordPress-Handbuch
WordPress-Handbuch / listing-18-2.php
Last active July 30, 2020 15:41
WordPress hook to activate a basic maintenance mode showing a message for everybody but the administrator
function wh_maintenance_mode() {
if ( !is_user_logged_in() || !current_user_can('administrator') ) {
wp_die( 'Dritte Variante einer Wartungsseite', 'Wartung!', array( 'response' => '503'));
}
}
add_action( 'get_header', 'wh_maintenance_mode' );