Site logo

Archived topic

Featured Title aligned in the middle center of the Featured image

17 replies · Started by Yulia on September 21, 2019

Viewing posts 1–15 of 18

Hi, could you please answer one more question please? I've set the header with the title centered horizontally and assigned the height through the css. I need the method to align the title vertically too and if possible to display this type of header conditionally so only when the featured image actually exists. I assigned the height though the class of this header, so I worry if there's no this featured image then title will still be the usual height.

Thanks for the help.

And just to make sure, you don’t want the header element to show if there is no featured image uploaded for the post?

Correct, I need just a standard title instead.

To align page hero content vertically, simply add equal top and bottom padding:

What if the title consists of a few lines, then the height of the featured image won't be the same height all across the site and I need this feature.

Thanks for the guidance, I've created an Element Hook, pasted there the codes Tom provided, checked ID of the Header Element (from the Edit URL like http://saasvaluechain.smartleads.eu/wp-admin/post.php?post=160&action=edit&classic-editor), so I took 160, my code is

<?php 
add_filter( 'generate_header_element_display', function( $display, $element_id ) {
    if ( 160 === $element_id ) {
        if ( ! has_post_thumbnail() ) {
            $display = false;
        }
    }

    return $display;
}, 10, 2 );

or without the <?php

not working (checked the Display Rules too)

Mmm, added this way, but still doesn't work.

You don't need the <?php in the code but it shouldn't matter.

Can you make sure the snippet is indeed activated and all plugin and server cache is cleared?

Yes, in this plugin I inserted without <?php (though I only set it to check, I noticed that for Elements this is also not needed for a while already, so I don't use it there too).
I activated it, no cache plugins at all and everything reacts on changes instantly. Still nothing

Hmm can you try this?

add_filter( 'generate_header_element_display', function( $display, $element_id ) {
    if ( 160 === $element_id && ! has_post_thumbnail() ) {
            $display = false;
    }
    return $display;
}, 10, 2 );

Please double check the element ID.

Let me know :)

This one works, though I don't see why, if the first condition is true it will follow the next line. Great it works, though would be so nice to know why the first one doesn't. Thanks, appreciate the quality of support immensely

Honestly don't see why either. It was a shot in the dark...

Glad I could help :)

if only I set somewhere some extra spacing, but I copied the code, and the person who initially used it reported that it works.
Thanks for the shots :)

This archived topic is closed to new replies.