Joy
(@joyously)
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?
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.
Joy
(@joyously)
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.
Joy
(@joyously)
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?
Joy
(@joyously)
This looks like it does the same as you are
https://developer.ww.wp.xz.cn/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.ww.wp.xz.cn/reference/functions/has_custom_header/
which return actual boolean values and
https://developer.ww.wp.xz.cn/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.
Joy
(@joyously)
I also use a default of no image (passing just ”), and I use has_header_image and it works just fine.
I used has_header_image() and it worked!
@joyously thank you so much for taking the time to help me out. 🙂