A General Technology & Development Blog

Technology, Development, Programming – Magento, Wordpress.

Home » Best way to limit WordPress title length without plugin

Best way to limit WordPress title length without plugin

The best way to limit the WordPress title length without a plugin is to add code in to your themes functions.php file and call upon that function from within your theme template.

Here’s how to do it:

  1. Open functions.php in your theme
  2. Paste the following code in to functions.php:
    1. function max_title_length( $title ) {
      $max = 10;
      if( strlen( $title ) > $max ) {
      return substr( $title, 0, $max ). ” …”;
      } else {
      return $title;
      }
      }
    2. Note – you can change the value of 10, to the amount of characters you wish to limit by (including spaces).
  3. Paste this line of php code in to the file containing titles that you wish to limit, e.g. archive.php:
    1. add_filter( ‘the_title’, ‘max_title_length’);

Example Use:

You may wish to limit the size of titles if you are using a grid layout for your post archive, or main blog index.

This website (wploop), explains in more detail where you can apply this function.

  • Was this Helpful ?
  • Yes   No

Name of author

Name: BlogOwner

Short Bio: "The master has failed more times than the beginner has even tried."

eXTReMe Tracker