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-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-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-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-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-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-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-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-12.php
Last active April 11, 2019 07:03
Exchange the backend WordPress note in the footer with an own message, via filter hook in functions.php
function wh_wordpress_backend_footer () {
echo 'WordPress sauber installiert und konfiguriert dank des umfassenden und sagenhaften <a href="https://wordpress-handbuch.com" target="_blank">WordPress-Handbuchs</a></p>';
}
add_filter('admin_footer_text', 'wh_wordpress_backend_footer');
@WordPress-Handbuch
WordPress-Handbuch / listing-18-13.php
Last active April 11, 2019 07:05
Remove website field from WordPress' comment form through filter hook in functions.php
function wh_emove_url_from_comment_form( $fields ) {
unset( $fields['url'] );
return $fields;
}
add_filter( 'comment_form_default_fields', 'wh_remove_url_from_comment_form' );
@WordPress-Handbuch
WordPress-Handbuch / listing-18-14.php
Last active April 11, 2019 07:06
Anti spam measure: Remove all links in WordPress comments when the comment form is being submitted, using a filter hook
function wh_remove_comment_links( $content ) {
global $allowedtags;
$tags = $allowedtags;
unset( $tags['a'] );
$content = addslashes( wp_kses( stripslashes( $content ), $tags ) );
return $content;
}
add_filter( 'pre_comment_content', 'wh_remove_comment_links' );