• Resolved CineWars

    (@max1138)


    Hello,

    First off, great plugin.

    I am using a code snippet in which I want the Title length to be FULL on the single post but truncated on the the Homepage

    Using conditional logic the conditions I have set are

    Show This code snippet if

    Type of page >> Is not >> Single post/page

    but when I check the posts, they’re still truncated on the single page.

    Help

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @max1138,

    Thank you for your feedback, we’re happy to hear you like the plugin!

    Regarding the snippet – I suspect the issue is related to the location where you load the snippet – if you use the “Run Everywhere” option some of the conditional logic is not available, please try using the “Site Wide Header” location so that the page-specific info is loaded.

    We are working on a solution to avoid this issue in a future release.

    Thanks

    Thread Starter CineWars

    (@max1138)

    It still shows full title on main page even using that fix.

    I’m sure it’s just me not understanding things correctly.

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @max1138,

    Would it be possible to share the code of the snippet you are using to truncate the title so we can run some tests with different settings on our end?

    Thanks

    Thread Starter CineWars

    (@max1138)

    Sure thing:

    function max_title_length( $title ) {
    $max = 62;
    if( strlen( $title ) > $max ) {
    return substr( $title, 0, $max ). " …";
    } else {
    return $title;
    }
    }
     
    add_filter( 'the_title', 'max_title_length');

    Obviously, using it as a php snippet has the code as

    <?php
    function max_title_length( $title ) {
    $max = 62;
    if( strlen( $title ) > $max ) {
    return substr( $title, 0, $max ). " …";
    } else {
    return $title;
    }
    }
     
    add_filter( 'the_title', 'max_title_length');

    I wanted to use this code below as wpbeginner say:

    This method gives you more control over where your titles are shortened

    But I wanted to see if the above worked first:

    <a href="<?php the_permalink() ?>">
    <?php
    $thetitle = $post->post_title; /* or you can use get_the_title() */
    $getlength = strlen($thetitle);
    $thelength = 25;
    echo substr($thetitle, 0, $thelength);
    if ($getlength > $thelength) echo "...";
    ?>
    </a>
    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @max1138,

    Thank you for the details.

    I tried the snippet with the settings suggested above but 1 thing I had to adjust was the length limit. None of my titles reached 62 characters so none were getting cut off, I would suggest maybe trying something like 20 to make it more obvious when testing to find the perfect length for your layout.

    The second thing I suggest is maybe combining 2 rules like this: https://a.supportally.com/i/MjaLUO

    This should avoid a false positive when your homepage is set to a single page.

    Thread Starter CineWars

    (@max1138)

    That worked a treat, thank you.

    ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Correct Option to choose’ is closed to new replies.