Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #287813
    Tsavo
    Participant

    Hey guys,

    How can I configure WordPress/X Theme to truncate post titles automatically if they are over 25 words? I want to have some sort of (…More) link pop up to the post when post titles are over 25 words.

    Thanks!

    #288163
    Rue Nel
    Moderator

    Hello There,

    Thanks for posting in!

    To truncate post titles automatically, please add the following css code in the customizer, Appearance > Customize > Custom > CSS or insert this code in your child theme’s style.css (if you are using a child theme)

    .hentry .entry-title {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    Using css will not allow you to determine if it is already over 25 characters. The css will only check if the characters is beyond the borders of the container element. You will need a js script if you want the title to adjust to a precise number of words. Please try looking for a plugin that may help you.

    If you want to adjust the except length of your excerpt, you can set it in the customizer, Appearance > Customize > Blog > Content > Excerpt Length

    Hope this helps. Kindly let us know.

    #289313
    Tsavo
    Participant

    By “plugin” do you mean custom CSS in JavaScript section? Or an actual WordPress plugin?

    Does the “excerpt length” section in the customizer apply to both the post content and title? It doesn’t seem to change anything when I input a number.

    Thanks!

    #290047
    Nico
    Moderator

    Hi There,

    In regards to the excerpt length, Would you mind sharing us your admin credentials so we could check your current setup.

    Don’t forget to set it as private reply.

    Thank you so much.

    #290245
    Tsavo
    Participant
    This reply has been marked as private.
    #290904
    Christopher
    Moderator

    Hi there,

    #1 Please remove following code from Customize -> custom -> JavaScript :

    .wpcf7 input[type="text"],
    .wpcf7 input[type="email"],
    .wpcf7 textarea
    {
          border: 1px solid #d3d3d3;
    border-radius: 3px;
          padding: 0px 0;
    }

    And put it in CSS section.

    #2 I searched for provide post title and the result didn’t show that specific post.
    http://loglineit.com/wp-admin/edit.php?s=loglines&post_status=all&post_type=post&action=-1&m=0&cat=0&seo_filter&paged=1&mode=list&action2=-1

    But upon checking some posts I see you added only a few words like two words in posts, so increase your content on these posts and test again.

    Hope it helps.

    #291234
    Tsavo
    Participant

    Sorry, I don’t know if I was being clear enough.

    Each post on my site will have little to no words in the post content, as the post titles themselves ARE the content. So what is contained inside the post does not need to be truncated, but rather the post title only.

    I tried out the excerpt length and it does indeed work correctly, albeit for the post content and not the title. I just want to figure out a way to truncate only the post titles if they are > 25 words.

    Is this possible with a WordPress plugin? JS script in the customizer? Or perhaps some custom CSS?

    Thanks!

    #291804
    Rad
    Moderator

    Hi there,

    Thanks for writing in.

    Excerpt length is only applicable for excerpts. Perhaps, you can try this out.

    Add this code at your child theme’s functions.php

    function limited_title ( $post_title ) {
       $post_title = explode(' ', $post_title , 25 );
       if ( count( $post_title )>= 25 ) {
          array_pop( $post_title );
          $post_title = implode( " " , $post_title).'.';
       } else {
          $post_title = implode( " " , $post_title );
       } 
       $post_title = preg_replace('<code>\[[^\]]*\]</code>','', $post_title );
       return $post_title;
    }
    
    add_filter( 'the_title', 'limited_title', 9999 );

    Hope this helps.

  • <script> jQuery(function($){ $("#no-reply-287813 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>