Support » Developing with WordPress » shape custom-background with css

  • helvetica123

    (@helvetica123)


    i want to create a theme has background image that is changeable by admin.for this goal i added that code to my function.php:

    $defaults = array(
        'default-color'          => '',
        'default-image'          => '',
        'default-repeat'         => 'no-repeat',
        'default-position-x'     => 'center',
            'default-position-y'     => 'fixed',
            'default-size'           => 'fixed',
        'default-attachment'     => 'scroll',
        'wp-head-callback'       => '_custom_background_cb',
        'admin-head-callback'    => '',
        'admin-preview-callback' => ''
    );
    add_theme_support( 'custom-background', $defaults );

    but these codes changed my design which created with css.the theme is based on parallax so if css doesnt work, all theme will waste.

    here is the css:

    /* parallax */   #home {
      background: url(<?php get_background_image(); ?>) no-repeat center center fixed; 
      display: table;
      height: 100%;
      position: relative;
      width: 100%;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;
    }

    so how can shape the function with css? thank you for your helps

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Joy

    (@joyously)

    I do it more like this:

    add_theme_support( 'custom-background',
    		apply_filters( 'mytheme_custom_background_args', array(
    			'default-color' => $default_colors['background_color'],
    			'default-image' => '',
    			'wp-head-callback' => 'mytheme_custom_background_style',
    	) ) );

    and generate the CSS for the custom background in your mytheme_custom_background_style function.

    helvetica123

    (@helvetica123)

    thank you for your reply but i dont know how to generate css for a function.can you tell me?

    Joy

    (@joyously)

    Look at how WP does it
    https://developer.wordpress.org/reference/functions/_custom_background_cb/

    or almost any theme in the WP repository.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.