Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Last active April 29, 2016 22:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-hiroshi/1dc18d5cbf4271a863291f27e8bbcc1a to your computer and use it in GitHub Desktop.
Save s-hiroshi/1dc18d5cbf4271a863291f27e8bbcc1a to your computer and use it in GitHub Desktop.
WordPressのカスタムヘッダー(custom header)登録サンプルです。
<?php
/**
* カスタム
*
* @package InfoTown
* @author Hiroshi Sawai <info@info-town.jp>
* @copyright Hiroshi Sawai
*/
class MyTheme_SetUp {
/**
* Add custom header.
*
* @since 1.0
*/
function register_custom_header() {
$args = array(
'width' => 1140,
'height' => 330,
'header-text' => true,
'default-text-color' => '333333',
'default-image' => esc_url( get_stylesheet_directory_uri() . '/images/default.jpg' ),
'random-default' => false,
);
$args = apply_filters( 'custom_header_args', $args );
if ( function_exists( 'get_custom_header' ) ) {
add_theme_support( 'custom-header', $args );
} else {
define( 'NO_HEADER_TEXT', true );
define( 'HEADER_TEXTCOLOR', $args['default-text-color'] );
define( 'HEADER_IMAGE', $args['default-image'] );
define( 'HEADER_IMAGE_WIDTH', $args['width'] );
define( 'HEADER_IMAGE_HEIGHT', $args['height'] );
$args['wp-head-callback'];
$args['admin-head-callback'];
add_theme_support( 'custom-background', $args );
}
}
}
<?php
// Support custom header.
$setup = new MyTheme_SetUp();
add_action( 'after_setup_theme', array($setup, 'register_custom_header' ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment