_custom_background_cb

Default custom background callback.

Description

_custom_background_cb(); 

Usage

  1. if ( !function_exists( '_custom_background_cb' ) ) { 
  2. require_once ABSPATH . WPINC . '/theme.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = _custom_background_cb(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/theme.php  
  1. function _custom_background_cb() { 
  2. // $background is the saved custom image, or the default image. 
  3. $background = set_url_scheme( get_background_image() ); 
  4.  
  5. // $color is the saved custom color. 
  6. // A default has to be specified in style.css. It will not be printed here. 
  7. $color = get_background_color(); 
  8.  
  9. if ( $color === get_theme_support( 'custom-background', 'default-color' ) ) { 
  10. $color = false; 
  11.  
  12. if ( ! $background && ! $color ) { 
  13. if ( is_customize_preview() ) { 
  14. echo '<style type="text/css" id="custom-background-css"></style>'; 
  15. return; 
  16.  
  17. $style = $color ? "background-color: #$color;" : ''; 
  18.  
  19. if ( $background ) { 
  20. $image = ' background-image: url("' . esc_url_raw( $background ) . '");'; 
  21.  
  22. // Background Position. 
  23. $position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); 
  24. $position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); 
  25.  
  26. if ( ! in_array( $position_x, array( 'left', 'center', 'right' ), true ) ) { 
  27. $position_x = 'left'; 
  28.  
  29. if ( ! in_array( $position_y, array( 'top', 'center', 'bottom' ), true ) ) { 
  30. $position_y = 'top'; 
  31.  
  32. $position = " background-position: $position_x $position_y;"; 
  33.  
  34. // Background Size. 
  35. $size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ); 
  36.  
  37. if ( ! in_array( $size, array( 'auto', 'contain', 'cover' ), true ) ) { 
  38. $size = 'auto'; 
  39.  
  40. $size = " background-size: $size;"; 
  41.  
  42. // Background Repeat. 
  43. $repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); 
  44.  
  45. if ( ! in_array( $repeat, array( 'repeat-x', 'repeat-y', 'repeat', 'no-repeat' ), true ) ) { 
  46. $repeat = 'repeat'; 
  47.  
  48. $repeat = " background-repeat: $repeat;"; 
  49.  
  50. // Background Scroll. 
  51. $attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); 
  52.  
  53. if ( 'fixed' !== $attachment ) { 
  54. $attachment = 'scroll'; 
  55.  
  56. $attachment = " background-attachment: $attachment;"; 
  57.  
  58. $style .= $image . $position . $size . $repeat . $attachment; 
  59. ?> 
  60. <style type="text/css" id="custom-background-css"> 
  61. body.custom-background { <?php echo trim( $style ); ?> } 
  62. </style> 
  63. <?php