Search code examples
javascriptcsswordpressredux-framework

How to change background image of body using redux framework in wordpress theme option?


I want to change my background image using redux-framework.I have used following codes, but its not working.First is my redux-code and second in my css code.If there is any alternate method please mention.

 array(
             'name' => "Background parttern",
            'id' => "background_parttern",
            'std' => "pattern11",
            'type' => "image_select",
            'title'    => __('Homepage Layout', 'personalblog'), 
            'subtitle' => __('Select Your Background Pattern.', 'personalblog'),
            'options' => array(
                'pattern1' => $personalblog_admin_img_dir . 'patterns/pattern1.png',
                'pattern2' => $personalblog_admin_img_dir . 'patterns/pattern2.png',

                'pattern54' => $personalblog_admin_img_dir . 'patterns/pattern54.png'  
                ),
             'output'    => array('background-image' => 'body' ),
              ),

CSS code:

body {
    font-family: 'Noto Serif', serif;
    font-size: 14px;
    background-image: url('image/patterns/pattern2.png');
    background-repeat: repeat;

}

Solution

  • You can use this code for the reference :-

    • First is redux-code
    array(
                'name' => "Background parttern",
                'id' => "background_parttern",
                'std' => "pattern11",
                'type' => "select_image",
                'title'    => __('Homepage Layout', 'personalblog'), 
                'subtitle' => __('Select Your Background Pattern.', 'personalblog'),
                'options' => Array(
                'pattern1' => 
                         Array ( 'alt'  => 'pattern1',
                                 'img'  => get_template_directory_uri() . 'image/patterns/pattern1.png',),
                'pattern2' => 
                         Array ('alt'  => 'pattern2',
                                'img'  =>get_template_directory_uri() . 'image/patterns/pattern2.png',
                               )
                    ),
                  'output'    => array('background-image' => 'body' ),
            ),
    
    • css code
    body {
              font-family: 'Noto Serif', serif;
              font-size: 14px;
              background-image: url("<?php echo '' . $redux_Options_name['background_parttern']; ?>");
              background-repeat: repeat;
         }
    

    I hope this will help you .