• i’ve gone through many sources seeking a simple solution to limit the number of letters or characters a subscriber can input into a post title field. Ideally entry input would stop once the limit was met-exceeded.

    I only want to allow 40 characters at which point the input of added characters would cease…

    I use the twenty-ten theme and primarily the wp-property plugin plus others.

    Any guidance or direction on this would be gratefully appreciated.

    thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • This is the code I used on a recent project, I had more than one such field, they were given css id of txtA, lenA, txtB, lenB and so on.

    You will have to workout how to change the form without changing core files. Maybe recode these two fields into the DOM using javascript.

    This is the code I put into the form:

    <input class="txt" id="txtA" onKeyUp="countChars(\'A\')" name="e_nf" type="text" size="35" max="40" value="'.$var[0][2].'"/>
     <input disabled size="3" id="lenA" class ="sz"/>

    This is the javascript code:

    echo '<script type="text/javascript">
    function countChars(nx) {
    	var txt = document.getElementById("txt"+nx);
    	var str = txt.value;
    	var l = txt.getAttribute(\'max\');
    	var len = str.length;
    	if(len <= l) {
    		document.getElementById("len"+nx).value=(len)+" / "+l;
    	} else {
    		txt.value=str.substr(0, l);
    	}
    }
    </script>';

    nvm. i thought excerpt

    Thread Starter jimii

    (@jimii)

    i want to thank you both – these suggestions are both beyond my abilities – : ) while Ive learned allot in the last two years – coding detail like this is not my strength yet.

    i simply want that when subscribers are inputting a post_title for the plugin, after x characters they can’t input anymore. The title wont go on forever and it should become clear to them they need to use fewer characters and

    Presently it WP functions in a reverse manner – people could publish a book chapter within the title field. I would have thought wordpress would have put an automatic stop point in with a switch to allow people to ‘open it up as necessary”. Thank you again – I’ll continue to search and study. : )

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to Limit number of characters in a Post Title’ is closed to new replies.