Super Child Themes
Immer Child Themes brauchen!
Nur gute Child Themes können von alles schutzen
CSS - style.css
Widgets
Plugins
Hooks:
Actions,
Filters
// WP Core wp-settings.php
do_action( 'after_setup_theme' );
// Twenty Fifteen functions.php
if ( ! function_exists( 'twentyfifteen_setup' ) ) {
/**
* Sets up theme defaults and registers support for various WordPress features.
*/
function twentyfifteen_setup() {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 825, 510, true );
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'twentyfifteen' ),
) );
}
}
add_action( 'after_setup_theme', 'twentyfifteen_setup' );
Parent: actions
// Twenty Fifteen Child functions.php
/**
* Adds theme support for post formats.
*/
function twentyfifteen_child_setup() {
add_theme_support( 'post-formats', array(
'aside',
'quote',
) );
}
add_action( 'after_setup_theme', 'twentyfifteen_child_setup' );
Child: actions
Ladungs Reihenfolge
/twentyfifteen-child/functions.php
/twentyfifteen/functions.php
// Twenty Fifteen functions.php
if ( ! function_exists( 'twentyfifteen_setup' ) ) {
...
}
// Twenty Fifteen Child functions.php
/**
* Sets up theme defaults and registers support for various WordPress features.
* Overwrites the parent theme function
*
*/
function twentyfifteen_setup() {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 825, 510, true );
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'twentyfifteen' ),
) );
}
add_action( 'after_setup_theme', 'twentyfifteen_setup' );
Child: pluggable actions
// WP Core wp-includes/formatting.php
apply_filters( 'excerpt_more', ' ' . '[…]' );
// Twenty Fifteen inc/template-tags.php
/**
* Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link.
*
* @since Twenty Fifteen 1.0
*
* @return string 'Continue reading' link prepended with an ellipsis.
*/
function twentyfifteen_excerpt_more( $more ) {
$link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
esc_url( get_permalink( get_the_ID() ) ),
/* translators: %s: Name of current post */
sprintf( __( 'Continue reading %s', 'twentyfifteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
);
return ' … ' . $link;
}
add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' );
Parent: filters
// return "..."
function twentyfifteen_child_excerpt_more( $more ) {
return $more;
}
add_filter( 'excerpt_more', 'twentyfifteen_child_excerpt_more' );
// return "... Continue reading Hello World"
function twentyfifteen_excerpt_more( $more ) {
$link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
esc_url( get_permalink( get_the_ID() ) ),
/* translators: %s: Name of current post */
sprintf( __( 'Continue reading %s', 'twentyfifteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
);
return ' … ' . $link;
}
add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' );
Child: filters
// Child Theme
function twentyfifteen_excerpt_more() {
}
add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' );
// Parent Theme
if ( ! function_exists( 'twentyfifteen_excerpt_more' ) && ! is_admin() ) :
/**
* Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link.
*
* @since Twenty Fifteen 1.0
*
* @return string 'Continue reading' link prepended with an ellipsis.
*/
function twentyfifteen_excerpt_more( $more ) {
$link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
esc_url( get_permalink( get_the_ID() ) ),
/* translators: %s: Name of current post */
sprintf( __( 'Continue reading %s', 'twentyfifteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
);
return ' … ' . $link;
}
add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' );
endif;
Child: Pluggable filters
action/filter entfernen
// Parent Theme
add_action( 'after_setup_theme', 'twentyfifteen_setup' );
// Child Theme
remove_action( 'after_setup_theme', 'twentyfifteen_setup', 11 );
// Parent Theme
add_filter( 'excerpt_more', 'twentyfifteen_excerpt_more' );
// Child Theme
remove_filter( 'excerpt_more', 'twentyfifteen_excerpt_more', 11 );
Prioritäten
// Child Theme
remove_action( 'after_setup_theme', 'twentyfifteen_setup', 11 );
remove_filter( 'excerpt_more', 'twentyfifteen_excerpt_more', 11 );
function twentyfifteen_child_remove_scripts(){
wp_dequeue_style( 'twentyfifteen-ie7' );
}
add_action( 'wp_enqueue_scripts', 'twentyfifteen_child_remove_scripts', 11 );
function twentyfifteen_child_setup() {
...
}
add_action( 'after_setup_theme', 'twentyfifteen_child_setup', 11 );
function twentyfifteen_child_excerpt_more( $more ) {
...
}
add_filter( 'excerpt_more', 'twentyfifteen_child_excerpt_more', 11 );
THA: Theme Hooks Alliance
<?php tha_entry_before(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php tha_entry_top(); ?>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h1>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content">
<?php
/* translators: %s: Name of current post */
the_content( sprintf(
__( 'Continue reading %s <span class="meta-nav">→</span>', '_s' ),
the_title( '<span class="screen-reader-text">"', '"</span>', false )
) );
?>
</div><!-- .entry-content -->
<footer class="entry-footer">
<?php _s_entry_footer(); ?>
</footer><!-- .entry-footer -->
<?php tha_entry_bottom(); ?>
</article><!-- #post-## -->
<?php tha_entry_after(); ?>
Seiten Templates
<?php
/**
* Template Name: Full Width Page
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
http://example.com/blog/category/bern/
- category-ben.php
- category-4.php
- category.php
- archive.php
- index.php
Beispiel
/*
* Include the Page template for the content.
* If you want to override this in a child theme, then include a file
* called content-page.php and that will be used instead.
*/
get_template_part( 'content', 'page' );
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
Theme spezifische Hirarchie
Referenzen
Super Child Themes
By Ulrich Pogson
Super Child Themes
- 2,141