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-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-6-2.css
Last active December 4, 2020 08:16
Code fragment for ribbon include example – CSS part
.ribbon {
width: 150px;
height: 150px;
overflow: hidden;
position: absolute;
z-index:9;
}
.ribbon span {
position: absolute;
@WordPress-Handbuch
WordPress-Handbuch / listing-18-17.php
Created April 23, 2019 06:09
WordPress 5 dropin for db-error.php, a custom error message in case of a failed database connection
<?php ob_start();
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
mail("info@ihredomain", "Datenbankfehler", "Schon wieder die Datenbank!", "From: Meine Website");
?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Website nicht erreichbar</title>
@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-22-1.php
Last active February 18, 2020 19:55
WordPress 5 plugin main php code of the WH Eyecatcher example project https://wordpress.org/plugins/wh-eyecatcher/
<?php
/*
Plugin Name: WH Eyecatcher
Plugin URI: https://wordpress-handbuch.com/wh-eyecatcher
Description: Add a floating slogan to eyery page of your website
Version: 1.0.2
Author: WordPress-Handbuch
Author URI: https://wordpress-handbuch.com
License: GPL v2 or later
Copyright 2019 Richard Eisenmenger
@WordPress-Handbuch
WordPress-Handbuch / listing-19-1.php
Last active February 18, 2020 18:12
WordPress 5 – Register new post type in an own plugin
<?php
/**
* Plugin Name: WH Custom Post Type
*/
function add_wh_events() {
$labels = array(
'name' => 'Veranstaltungen',
'singular_name' => 'Veranstaltung',
'add_new' => 'Erstellen',
'add_new_item' => 'Neue Veranstaltung erzeugen',
@WordPress-Handbuch
WordPress-Handbuch / listing-18-1.php
Created December 14, 2018 13:23
WordPress 5 Plugin: WH_Hello_World
<?php
/**
* @package WH_Hello_World
* @version 1.0.0
*/
/*
Plugin Name: WH Hello World
Plugin URI: https://wordpress-handbuch.com
Description: Testausgabe in Front- und Backend
Author: Richard Eisenmenger
@WordPress-Handbuch
WordPress-Handbuch / listing-10-2.php
Last active September 4, 2019 07:53
PHP/HTML blog snippet for proper WordPress HTML meta tag integration for social network sharing
<?php
if (is_single())
{
$title = htmlspecialchars( strip_tags( get_the_title( $post->ID ) ) );
$description = htmlspecialchars( strip_tags( get_the_excerpt( $post->ID ) ) );
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
$image = $thumbnail[0];
$type = 'article';
} elseif (is_page()) {
$title = htmlspecialchars( strip_tags( get_the_title( $post->ID ) ) );
@WordPress-Handbuch
WordPress-Handbuch / listing-15-4.htaccess
Last active May 19, 2019 09:36
Show all ways to get the current and absolute PHP script folder
AuthUserFile /AbsoluterPfadZumIhremWordPressAdminOrdner/.htpasswd
AuthType Basic
AuthName "Verhaeltnismaessig geheimer Zugang zur Website"
Require valid-user
<?php
echo 'basename(dirname(__FILE__)) = ' . basename(dirname(__FILE__)) . "<br/>";
echo '$_SERVER["PHP_SELF"] = ' . $_SERVER["PHP_SELF"] . "<br/>";
echo '$_SERVER["DOCUMENT_ROOT"] = ' . $_SERVER["DOCUMENT_ROOT"] . "<br/>";
echo 'dirname(__FILE__) = ' . dirname(__FILE__) . "<br/>";
echo 'getcwd() = ' . getcwd() . "<br/>";
echo '__FILE__ = ' . __FILE__ . "<br/>";
phpinfo();
?>