返回介绍

get_background_image()

发布于 2017-09-10 22:51:00 字数 3056 浏览 1330 评论 0 收藏 0

get_background_image()

Retrieve background image for custom background.


description


返回值

(string)


源代码

File: wp-includes/theme.php

function get_background_image() {
	return get_theme_mod('background_image', get_theme_support( 'custom-background', 'default-image' ) );
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: get_theme_support()
  • wp-includes/theme.php: get_theme_mod()

Used By

  • wp-admin/includes/template.php: _media_states()
  • wp-admin/custom-background.php: Custom_Background::admin_page()
  • wp-includes/theme.php: background_image()
  • wp-includes/theme.php: _custom_background_cb()
  • wp-includes/theme.php: _delete_attachment_theme_mod()
  • wp-includes/post-template.php: get_body_class()
  • Show 1 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Use Theme Background Image as Fallback if No Featured Image Exists

    This example could be used to detect whether the current Page/Post has a Featured Image set – if so, it will use the Featured Image as the page background, if not it will use the current active theme’s default background image. As is, this should be used in the of the page template, just after the call to wp_head():

    
    // Declare $post global if used outside of the loop.
    $post = get_post();
    
    // check to see if the theme supports Featured Images, and one is set
    if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) {
            
        // Specify desired image size in place of 'full'.
        $page_bg_image     = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
        $page_bg_image_url = $page_bg_image[0]; // This returns just the URL of the image.
    
    } else {
        // The fallback – our current active theme's default bg image.
        $page_bg_image_url = get_background_image();
    }
    
    // And below, spit out the <style> tag... ?>
    <style type="text/css" id="custom-background-css-override">
        body.custom-background { background-image: url('<?php echo $page_bg_image_url; ?>'); }
    </style>
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文