Wordpress Titles: If Longer Than 50 Characters, Show Ellipsis

前端 未结 9 1312
谎友^
谎友^ 2021-02-01 19:06

I have a wordpress site with titles, and if the title has more than 50 characters I need to add an ellipsis (...) at the end of the title and stop the title at 50 characters. Be

9条回答
  •  走了就别回头了
    2021-02-01 19:44

    WordPress has built in function "wp_trim_words()" to trim the sentences based on the number of words you provide, If you want to trim by words then this function may help you.

    https://codex.wordpress.org/Function_Reference/wp_trim_words

    to trim the title longer than 5 words you can do this

    '.$short_title.'';
    ?>
    

提交回复
热议问题