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-22-2.css
Created March 22, 2019 11:33
The meta tags for building a WordPress theme's style.css file from the scratch
/*
Theme Name: WH HTML Theme
Theme URI: https://wordpress-handbuch.com
Author: WordPress-Handbuch
Author URI: https://wordpress-handbuch.com
Description: Just the meta tags for building a style.css file from the scratch
Version: 0.1
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: whhtmltheme
@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-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-19-5.php
Last active April 10, 2019 09:29
Adding a custom taxonomy wh_eventtype to the custom post type wh_event (WordPress 5 needs show_in_rest for the metaboxes to appear)
<?php
/**
* Plugin Name: WH Custom Post Type
* Version: 0.4
*/
function add_wh_events() {
$labels = array(
'name' => 'Veranstaltungen',
'singular_name' => 'Veranstaltung',
'add_new' => 'Erstellen',
@WordPress-Handbuch
WordPress-Handbuch / listing-19-4.php
Last active April 10, 2019 09:22
Replace custom post type overview columns with custom fields from the meta-box configuration (WordPress 5 example for event dates and locations)
<?php
/**
* Plugin Name: WH Custom Post Type
* Version: 0.3
*/
function add_wh_events() {
$labels = array(
'name' => 'Veranstaltungen',
'singular_name' => 'Veranstaltung',
'add_new' => 'Erstellen',
@WordPress-Handbuch
WordPress-Handbuch / listing-19-3.php
Created March 14, 2019 09:36
Extending a WordPress theme's single.php template file to output custom post fields (meta-boxes), (tested for Twenty Nineteen)
if ( $custom = get_post_custom() ) {
$location = ( isset($custom['location'][0] )) ? 'in ' . $custom['location'][0] : '';
$eventdate = ( isset($custom['eventdate'][0] )) ? 'am ' . date_i18n(get_option( 'date_format' ), strtotime($custom['eventdate'][0])) : '';
if ( !empty( $location ) || !empty ($location)) {
echo ' <h3 class="comments-area">Veranstaltung ' . $location . ' ' . $eventdate . '</h3>';
}
}
@WordPress-Handbuch
WordPress-Handbuch / listing-19-2.php
Last active April 10, 2019 09:12
Extending a custom post type by custom fields through the meta-box mechanism (WordPress 5 verified)
<?php
/**
* Plugin Name: WH Custom Post Type
* Version: 0.2
*/
function add_wh_events() {
$labels = array(
'name' => 'Veranstaltungen',
'singular_name' => 'Veranstaltung',
'add_new' => 'Erstellen',
@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');