Custom trim my post title item combine two if

Question Php Logic :

I want to trim my post title, i'm still learning php.. how to combine the two if?

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'post_title' == $item['source']) {
        }
    if (strlen($value) > 120) {
        $value = substr( $value, 0, 120) . '…';
    }
    return $value;
}, 10, 2 );

EDIT :

I tried that

add_filter( 'facetwp_builder_item_value', function( $value, $item ) {
    if ( 'post_title' == $item['source'] && (strlen($value) > 120)) {
        $value = substr( $value, 0, 120 ) . '…';
    }
    return $value;
}, 10, 2 );

but it seems to not always work it has trouble working

logically if the title exceeds 120 then you limit to 120. that's right, isn't it?



Read more here: https://stackoverflow.com/questions/66321602/custom-trim-my-post-title-item-combine-two-if

Content Attribution

This content was originally published by neosan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: