get_background_image() - WordPress 函数参考中文文档

返回介绍

get_background_image()

发布于 2017-09-10 字数3056 浏览 907 评论 0

get_background_image()

Retrieve background image for custom background.


描述


返回值

(string)


源代码

File: wp-includes/theme.php

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

更新日志

Version 描述
3.0.0 Introduced.

相关函数

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>
    

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!