How do I limit the number of characters in a post title? I’ve seen it done in Yoast’s WordPress SEO plugin but I want to do something similar for the WP title.
I checked out a plugin called Limit a post title to X characters but it seems like it’s been abandoned and it also breaks the Edit Media page since the media too has a title.
You could do this :
You can replace
strlen()
withstr_word_count()
if you want to set a word limit instead.EDIT: ok with new details you added it seems you could add some jQuery to do the same (strlen)
On a new post, the title is set in
<input type="text" name="post_title" size="30" value="" id="title" autocomplete="off">
.Using a jQuery plugin like http://unwrongest.com/projects/limit/, you could write a WP plugin that targets the
post_title
and sets the limit right from the editor page.You could also add a function in your theme’s
functions.php
file instead of a plugin, depending on if you want to tie it in to the theme or the site.This method makes it possible to keep original length titles if you decided to disable the plugin or change themes.
I tried with this plugin, It’s worked for me.
https://wordpress.org/plugins/limit-post-titles/