How to set character limit on the_content() in wordpress

 

Welcome to wp-feed article, follow the below important wp feed for wp tips and tricks.

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

<?php   
  add_filter("the_content", "plugin_myContentFilter");

  function plugin_myContentFilter($content)
  {
    // Take the existing content and return a subset of it
    return substr($content, 0, 300);
  }
?>

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.

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

Thank you. We hope this short wp feed article helped you learn more about wordpress.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *