wordpress功能集成(十五):主题自定义头部功能
新版本的wordpress自定义头部功能和自定义背景很像,自3.4版本后,为主题添加自定义头部功能方法很简单那,只需要往主题的functions.php中添加代码:
- add_theme_support( ‘custom-header’ );
同样的,你也可以使用一些参数来设置默认选项:
- $defaults = (
- ‘-image’ => ”,
- ‘random-‘ => false,
- ‘width’ => 0,
- ‘height’ => 0,
- ‘flex-height’ => false,
- ‘flex-width’ => false,
- ‘-text-color’ => ”,
- ‘header-text’ => true,
- ‘uploads’ => true,
- ‘wp-head-callback’ => ”,
- ‘admin-head-callback’ => ”,
- ‘admin-preview-callback’ => ”,
- );
- add_theme_support( ‘custom-header’, $defaults );
实例:设置一个默认的头部图像,
- $args = (
- ‘width’ => 980,
- ‘height’ => 60,
- ‘-image’ => get_template_directory_uri() . ‘/images/header.jpg’,
- );
- add_theme_support( ‘custom-header’, $args );
允许上传新图像:
- $args = (
- ‘width’ => 980,
- ‘height’ => 60,
- ‘-image’ => get_template_directory_uri() . ‘/images/header.jpg’,
- ‘uploads’ => true,
- );
- add_theme_support( ‘custom-header’, $args );
输出一个大小可变的头部图像:
- $args = (
- ‘flex-width’ => true,
- ‘width’ => 980,
- ‘flex-width’ => true,
- ‘height’ => 200,
- ‘-image’ => get_template_directory_uri() . ‘/images/header.jpg’,
- );
- add_theme_support( ‘custom-header’, $args );
后台的设置都做好了,前台调用设置选项的方法:
- <img src=“<?php header_image(); ?>” height=“<?php echo get_custom_header()->height; ?>” width=“<?php echo get_custom_header()->width; ?>” alt=“” />
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END