• Resolved alex-codes

    (@greenonion8)


    Hi,
    I am a developer of the wordpress theme in question. I updated my theme recently and checking now the theme looks in the theme preview in the theme directory I noticed that .header-img body class keeps being added in the preview although there is no header image in the preview!
    I have several body classes (like .header-img or .sidebar-left) that are added when certain condition is true via customizer. The code for adding the class:

    if ( get_header_image() !== false ) {
    $classes[] = ‘header-img’;
    }

    This class is responsible for completely different header styles (margin etc.) than when the theme has no header image. So right now the theme in the preview looks weird with huge spacing above and below the header which shouldn’t be there if not for this class.

    Apart from theme preview that is if the theme is downloaded and installed the issue doesn’t appear any more.
    The theme files are here: https://themes.svn.www.ads-software.com/actinia/2.1.2/
    The body classes are managed in inc/extras.php

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • Are you saying that the preview site has set an image, but the image is not available? Or that the preview site has a class the same name as yours?
    Or perhaps your theme is using the wrong default value?

    Thread Starter alex-codes

    (@greenonion8)

    The preview site isn’t setting an image. It’s just adding the .header-img class to the body of the theme for some reason. This class should only be added if a header-image is set. This class provides special styles to the header which are unnecessary if there is no header image.

    The theme has no default value at all and it has no default header image. The classes are added only if the corresponding conditions are matched. For example if there is no navigation bar, .no-menu class is being added to the body, if there is a header image, .header-img class is being added etc.

    The .header-img class is added only if the following condition is matched:

    if ( get_header_image() !== false ) {
    $classes[] = ‘header-img’;
    }

    Apparently the condition is true in the preview, although there is no header image there! I am trying to understand why the condition is true so that I can find some workaround.

    The theme has no default value at all and it has no default header image.

    The theme should always have a default value. If the theme does not call add_theme_support( 'custom-header'), then it should not have the code for that body class. And if it does call it, it should have default values.

    The false value is only returned if the header is being removed.
    https://developer.www.ads-software.com/reference/functions/get_header_image/

    Thread Starter alex-codes

    (@greenonion8)

    Sorry, I misunderstood you. This is the default value:

    function actinia_custom_header_setup() {
    	add_theme_support(
    		'custom-header',
    		apply_filters(
    			'actinia_custom_header_args',
    			array(
    				'default-image'       => '',
    				'default-text-color'  => '000000',
    				'width'               => 1500,
    				'flex-width'          => true,
    				'height'              => 200,
    				'flex-height'         => true,
    				'wp-head-callback'    => 'actinia_header_style',
    			)
    		)
    	);
    }

    The false value is only returned if the header is being removed.

    Is there any other way to make sure the class is only added if there really is a header image?

    This looks like it does the same as you are
    https://developer.www.ads-software.com/reference/functions/has_header_image/
    which would have the same trouble (” is falsey and ‘remove-header’ is the only real false).

    Used by https://developer.www.ads-software.com/reference/functions/has_custom_header/
    which return actual boolean values and
    https://developer.www.ads-software.com/reference/functions/get_header_image_tag/
    which most would think is more accurate.

    Perhaps just change yours to use has_header_image or change how you check for !== false since that’s not the right thing to check for.

    I also use a default of no image (passing just ”), and I use has_header_image and it works just fine.

    Thread Starter alex-codes

    (@greenonion8)

    I used has_header_image() and it worked!
    @joyously thank you so much for taking the time to help me out. ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Theme preview issue – 2’ is closed to new replies.