How to set character limit on the_content() and the_excerpt() in wordpress

后端 未结 9 1337
臣服心动
臣服心动 2020-12-07 23:36

How do I set a character limit on the_content() and the_excerpt() in wordpress? I have only found solutions for the word limit - I want to be able to set an exact amount cha

9条回答
  •  借酒劲吻你
    2020-12-07 23:47

    Or even easier and without the need to create a filter: use PHP's mb_strimwidth to truncate a string to a certain width (length). Just make sure you use one of the get_ syntaxes. For example with the content:

    
    

    This will cut the string at 400 characters and close it with .... Just add a "read more"-link to the end by pointing to the permalink with get_permalink().

    Read more 
    

    Of course you could also build the read more in the first line. Than just replace '...' with '[Read more]'

提交回复
热议问题