• Goodmorning,

    This morning I added

    <?php add_theme_support( 'custom-background' ); ?>

    to my functions.php file. In WP (version 3.9.1) I am able to change de color of my background now, but changes don’t take place in the actual website bloedendpaard.nl

    I’m using Bootstrap as well. Does anyone know what could go wrong?

    Thank you!

    Frans

Viewing 4 replies - 1 through 4 (of 4 total)
  • For it to take effect the body tag needs to include the
    ‘custom-background’ class.

    The standard way of doing that is to use this in the template that creates your body tag (normally in header.php):
    <body <?php body_class(); ?>>

    Thread Starter FCJvanderVleuten

    (@fcjvandervleuten)

    Dear pyjamaman,

    Thanks for the help. I put the piece of code inside my header.php, but this line of code appeared on my screen while viewing the website:

    class="home blog logged-in admin-bar no-customize-support"

    What could it be? I checked my </>-tags etc but they all look fine. It looks like it’s been generated by a plug-in, because this piece of code is not in my php-files.

    When I look at your site, I notice that you have a few 404 errors: https://www.bloedendpaard.nl/001/css/bootstrap.min.css, https://www.bloedendpaard.nl/style.css, https://www.bloedendpaard.nl/css/bootstrap.min.css, and https://www.bloedendpaard.nl/001/style.css. Also, I don’t see the code you listed anywhere on your site. Did you change themes?

    Hi FCJvanderVleuten, you put the code in the wrong place. What you’re seeing on the screen is the output from <?php body_class(); ?> and should be inside the <body> tag. Looking at your page source as it is now you actually seem to have two body tags, but neither with any classes.

    Right click on your webpage and select ‘View Page Source’ (if the option isn’t there, try clicking on a more ‘blank’ part of the page). You’ll see the opening few tags – DOCTYPE, html, head…body – are repeated again further down.

    The class=”home blog logged-in admin-bar no-customize-support” should be inside the (only) body tag. body_class() creates the classes according to your current status, and if your custom background was working it should have added ‘custom-background’ to that list. Here’s some of the code that body_class() uses (indirectly):

    if ( is_user_logged_in() )
    	$classes[] = 'logged-in';
    
    if ( is_admin_bar_showing() ) {
    	$classes[] = 'admin-bar';
    	$classes[] = 'no-customize-support';
    }
    
    if ( get_theme_mod( 'background_color' ) || get_background_image() )
    	$classes[] = 'custom-background';

    It’s creating that list of classes, but in your case, it seems get_theme_mod( ‘background_color’ ) is false, so it’s not adding custom-background. I don’t know why.

    I think maybe you need to take a step back and get a better grasp of which php is creating your webpage, and how.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom background php-code in funtions.php not working.’ is closed to new replies.