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-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-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-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-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-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-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-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-4.css
Created March 26, 2019 07:38
Example Gutenberg editor styles to be included via add_editor_style( 'listing-21-4.css' );
body {
background-color: #00ffff;
color: #0000ff;
}
.wp-block {
max-width: 300px;
}
.wp-block[data-align="wide"] {
max-width: 500px;
}
@WordPress-Handbuch
WordPress-Handbuch / listing-21-3.php
Created March 26, 2019 08:11
Example functions.php with activated WordPress 5 features
<?php
/**
* WH HTML Vorlage functions and definitions
*
* @link @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WH_HTML_Vorlage
*/
/**
@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