wp/wordpress开启网站背景图/顶部图片
七娃博客1,040人阅读
wp除了可以自定义logo之外,还可以通过自定义——图像,设置网站的背景图/顶部图像,那么如何开启呢?不多逼叨,看代码步骤!
1.在functions.php,加入代码
//自定义顶部980*200图片 $args = array( 'flex-width' => true, 'width' => 980, 'flex-height' => true, 'height' => 200, 'default-image' => get_template_directory_uri() . '/images/header.jpg', //设置主题默认的顶部图片,用户没有上传时调用此图片 ); add_theme_support( 'custom-header', $args );
2.在需要调用的地方加入
<img alt="" src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>">
3.在后台——自定义——顶部图像上传图片——发布
然后刷新网站,就可以看到效果了!
评论 | 0 条评论
登录之后才可留言,前往登录