Support » Theme: OceanWP » Option to use conditional padding for post title

  • Resolved Milan

    (@mimoho)


    Asking for a way to define padding for post titles conditionally based on whether there is a feature image displayed in a post or not. When I define padding for the post title but do not insert a feature image, the post’s title is lowered anyways, although I’m just trying to create space between a feature image and the title.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author oceanwp

    (@oceanwp)

    By default there is a space between the title and image, can you send me the url of the post where you have this problem?

    Yes, there is some little space. But when I add a larger space to increase the gap on top of the post title to the feature image assuming that the image is set for the top position in a post, it is affecting also posts without feature image as I need to choose global custom CSS:
    }
    .entry-header {
    padding-top: 30px;
    }
    I’d like the margin to be there only when there is a feature image displayed in the post. It would help to get assistance for determining this in CSS, but a solution in OceanWP Settings -> Title for margin and a tick box for “enable only when feature image is present” would be preferable.

    Theme Author oceanwp

    (@oceanwp)

    Hi, I cannot add too many settings to not bloat the theme so I can only add necessary settings.
    You will need to add a class in the body if there is or not a featured image, then you will be able to do something like this:

    .custom-body-class .entry-header {
    padding-top: 30px;
    }

    To add the class, add this code in the functions.php file of your child theme:

    function prefix_body_classes( $classes ) {
    
    	if ( has_post_thumbnail() ) {
    		$classes[] = 'custom-body-class';
    	}
    
    	// Return classes
    	return $classes;
    
    }
    add_filter( 'body_class', 'prefix_body_classes' );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Option to use conditional padding for post title’ is closed to new replies.