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-16-3.php
Last active March 7, 2019 07:38
Code example to output cached and uncached content through the fragment cache in W3 Total Cache (WordPress plugin)
<?php
if (!defined('W3TC_DYNAMIC_SECURITY')) {
define('W3TC_DYNAMIC_SECURITY', 'geheimesgeheimnis');
}
?>
<!--mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> echo 'Gecachter Inhalt: ' . date("Y-m-d", time()); -->
<?php echo 'Live-Inhalt: ' . date("Y-m-d", time()); ?>
<!--/mfunc <?php echo W3TC_DYNAMIC_SECURITY; ?> -->
@WordPress-Handbuch
WordPress-Handbuch / listing-16-4.php
Created March 7, 2019 13:24
404 handler for WordPress search showing posts alternatives related to the page not found, and a search form
<?php
global $wp;
$urlquery = $wp->request;
$urlquery = preg_replace("/(\.*)(html|htm|php)$/","",$urlquery);
$parts = explode('/', $urlquery);
$keyword = end($parts);
echo 'Mal sehen, ob es zum Thema "' . $keyword . '" Blogbeiträge gibt...';
$query = new WP_Query( array( 's' => $keyword ) );
@WordPress-Handbuch
WordPress-Handbuch / listing-16-5.php
Created March 10, 2019 12:42
PHP/HTML code fragment to include Yoast SEO's breadcrumbs into any template (e. g. page.php or single.php)
<?php
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}
?>
@WordPress-Handbuch
WordPress-Handbuch / listing-17-1.sh
Created March 11, 2019 09:46
Four WP-CLI commands to install and test the tool, and to test the checksums of the WordPress core and all plugins
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
php wp-cli.phar core verify-checksums
php wp-cli.phar plugin verify-checksums --all
@WordPress-Handbuch
WordPress-Handbuch / listing-17-2.php
Created March 11, 2019 12:55
Removes WordPress 5 RPC service itself and the <link> from the HTML header
add_filter( 'xmlrpc_enabled', '__return_false' );
remove_action('wp_head', 'rsd_link');
@WordPress-Handbuch
WordPress-Handbuch / listing-17-3.htaccess
Created March 11, 2019 12:57
Disallow XMLRPC call in WordPress 5 by denying access through .htaccess configuration
<Files xmlrpc.php>
order allow,deny
deny from all
</Files>
@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' );
@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-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' );