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-16-2.htaccess
Last active May 8, 2019 06:11
Take Control of the HTTP Expiration Headers and disable ETags
<IfModule mod_expires.c>
ExpiresActive On
FileETag None
Header unset ETag
ExpiresDefault "access plus 1 month"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rdf+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
@WordPress-Handbuch
WordPress-Handbuch / listing-18-18.php
Created April 23, 2019 06:11
WordPress 5 dropin /wp-content/maintenance.php, a custom maintenance message when using the .maintenance-mechanism in the main directory
<?php
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Website wird gewartet</title>
</head>
@WordPress-Handbuch
WordPress-Handbuch / listing-21-1.php
Last active April 19, 2019 14:24
Basic functions.php for a Twenty Nineteen child theme
<?php
add_action( 'wp_enqueue_scripts', 'twentynineteen_child_enqueue_styles' );
function twentynineteen_child_enqueue_styles() {
$parent_style = 'twentynineteen-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'twentynineteen-child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
filemtime(get_stylesheet_directory() . '/style.css')
);
@WordPress-Handbuch
WordPress-Handbuch / listing-21-5.css
Created April 11, 2019 08:20
Example RWD breakpoints
/* CSS Styles ausserhalb der folgenden speziellen Media Querys sind fuer grosse Monitore, breiter als 1199px, vorgesehen */
@media all and (max-width: 1199px) {
/* CSS Styles fuer grosse Displays */
}
@media all and (max-width: 991px) {
/* CSS Styles fuer Tablets hochkant */
}
@media all and (max-width: 768px) {
/* CSS Styles fuer Smartphones, horizontal */
}
@WordPress-Handbuch
WordPress-Handbuch / listing-20-1.php
Last active April 11, 2019 07:18
Example WordPress 5 widget to display a configurable number of event entries from the database, originally populated through a new custom post type
<?php
/**
* @package WH_Event_Widget
* @version 1.0.0
*/
/*
Plugin Name: WH Event Widget
Plugin URI: https://wordpress-handbuch.com
Description: Anzeige aktueller Veranstaltungen
Author: Johannes Mustermann
@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' );
@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-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-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-16.php
Created April 11, 2019 06:46
Display new image sizes choices set through add_image_size() also in the backend in the right sidebar when editing an image
function wh_add_image_sizes_to_backend( $existingsizes ) {
$addsizes = array(
"wh-homepage-teaser" => 'WH Homepage Teaser',
"wh-landingpage-stage" => 'WH Landingpage Stage',
"wh-detailpage-feature" => 'WH Detailpage Feature'
);
$newsizes = array_merge( $existingsizes, $addsizes );
return $newsizes;
}
add_filter( 'image_size_names_choose', 'wh_add_image_sizes_to_backend' );