Skip to content

Instantly share code, notes, and snippets.

@WordPress-Handbuch
Created March 26, 2019 08:11
Show Gist options
  • Save WordPress-Handbuch/fbf725d3f353df92b531a2fcd3441607 to your computer and use it in GitHub Desktop.
Save WordPress-Handbuch/fbf725d3f353df92b531a2fcd3441607 to your computer and use it in GitHub Desktop.
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
*/
/**
* WH HTML Vorlage includes theme support for WordPress 5 features.
* This topic is covered in chapter 21 Theme Development of the WordPress-Handuch https://wordpress-handbuch.com
*/
if ( ! function_exists( 'wh_html_theme_setup' ) ) {
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function wh_html_theme_setup() {
add_theme_support( 'post-thumbnails' );
add_theme_support( 'align-wide' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'custom-background', array( 'default-image' => '%1$s/images/pic01.jpg', 'default-size' => 'cover' ) );
add_theme_support( 'custom-header', array( 'default-image' => '%1$s/images/pic01.jpg', 'width' => 100, 'uploads' => true ) );
add_theme_support( 'custom-logo', array( 'height' => 100, 'width' => 100 ) ) ;
add_theme_support( 'editor-color-palette', array( array( 'name' => 'Schwarz wie die Nacht', 'slug' => 'myblack', 'color' => '#000000' ), array( 'name' => 'Weiß wie Schnee', 'slug' => 'mywhite', 'color' => '#ffffff' ) ) );
add_theme_support( 'editor-font-sizes', array( array( 'name' => 'Klitzeklein', 'size' => 7, 'slug' => 'mysmall' ), array( 'name' => 'Gigantisch', 'size' => 50, 'slug' => 'mylarge' ) ) );
add_theme_support( 'editor-styles' );
add_editor_style( 'ihre-editor-styles.css' );
add_theme_support( 'dark-editor-style' );
add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ) );
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'title-tag' );
add_theme_support( 'wp-block-styles' );
}
add_image_size( 'stamp-size', 10, 10, true );
}
add_action( 'after_setup_theme', 'wh_html_theme_setup' );
/**
* Enqueue scripts and styles.
*/
function wh_html_theme_scripts_and_styles() {
wp_enqueue_style( 'wh-html-theme-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
wp_style_add_data( 'wh-html-theme-style', 'rtl', 'replace' );
wp_enqueue_style( 'wh-html-theme-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
wp_enqueue_script( 'wh-html-theme-custom', get_theme_file_uri( '/assets/js/main.js' ), array(), '1.1', true );
}
add_action( 'wp_enqueue_scripts', 'wh_html_theme_scripts_and_styles' );
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Twenty Nineteen, use a find and replace
* to change 'twentynineteen' to the name of your theme in all the template files.
*/
function wh_html_theme_translation() {
load_theme_textdomain( 'wh-html-theme', get_template_directory() . '/languages' );
load_child_theme_textdomain( 'wh-html-theme', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'wh_html_theme_translation' );
// This theme uses wp_nav_menu() in one location.
function wh_html_theme_nav_menus() {
register_nav_menus( array(
'primary' => __( 'In Ulm, um Ulm und um Ulm herum', 'wh-html-theme' ),
) );
}
add_action( 'after_setup_theme', 'wh_html_theme_nav_menus' );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function wh_html_theme_widgets_init() {
register_sidebar( array(
'name' => 'Seitenleiste',
'id' => 'sidebar-1',
'description' => __( 'Hier erscheint die Übersetzung für die Beschreibung im Backend', 'wh_html_theme' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'wh_html_theme_widgets_init' );
// In case you want to organize additional Theme and template related functions:
//require get_template_directory() . '/inc/template-tags.php';
//require get_template_directory() . '/inc/template-functions.php';
//require get_template_directory() . '/inc/customizer.php';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment