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

后端 未结 9 1334
臣服心动
臣服心动 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:38

    You could use a Wordpress filter callback function. In your theme's directory, create a file called functions.php and add the following in:

    
    

    The plugin_myContentFilter() function will be called each time you request the content of a post/page via the_content() - it provides you with the content as an input, and will use whatever you return from the function for subsequent output or other filter functions.

    You can also do the same for the_exercpt() - add_filter() and then a function to be used as a callback.

    See the Wordpress filter reference docs for more details.

提交回复
热议问题