• Resolved santebarleyreviewhq

    (@santebarleyreviewhq)


    Hi bdbrown,

    Sorry to direct this query to you. My site (https://santebarleyreview.com) have at least 10 slides on it and some of them – the title exceeds up to 2 to 3 lines (maybe in the future).

    I want to have only 1 line (need to cut the statement if it exceeds to 1 line). Can you help me please?

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi santebarleyreviewhq. I have a couple of ideas. I’ll get back to you tomorrow.

    I’m sure there are several ways to approach this. The easiest solution I was able to come up with uses a WP function to limit the number of words displayed in the title. This involves a change to content-featured.php, which you would make in your child theme.

    Find these lines of code towards the bottom of the file:

    <h2 class="post-title">
    	<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </h2><!--/.post-title-->

    Replace those 3 lines with this:

    <h2 class="post-title">
    
    <!-- BEGIN change to limit number of words in post title -->
    <!-- disable the original code
    	<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    -->
    <!-- remove the title and leave the anchor tag open -->
    	<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>">
    
    <!-- limit number of words in post title to 10 -->
    	<?php
    	$title = get_the_title();
    	$trimmed_title = wp_trim_words( $title, 10, '...' );
    	echo $trimmed_title;
    	?>
    
    <!-- close the anchor tag -->
    	</a>
    <!-- END change -->      
    
    </h2><!--/.post-title-->

    You can adjust the number of words by changing the function argument. There isn’t any way to know exactly how many words will fit on one line but you should be able to get pretty close. Let me know how that works.

    Thread Starter santebarleyreviewhq

    (@santebarleyreviewhq)

    Thank you so much…

    It works…. however, there are still words that goes to the next line even if i change it to 6 words only. Anyway this is fine with me. I can live with this.

    Still moving up and down thou… hehehe

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Need to have 1 line for the Title in the feature slide’ is closed to new replies.