Support » Plugin: Media Library Assistant » Force tags to lowercase

  • Hi,
    is there anyone who has an idea to force media tags to be saved as all lowercase from the input text field or add tag field?

    Installs with diffrent users, handle shift key diffrent and they will not remember any rule given by webmaster …

    My last resort is to set a keydown event listerner with jquery, on each input field that occurs in the backend for att. tags. But thats not fun…


Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author David Lingren


    You might be better off hooking filters such as 'pre_insert_term', $term, $taxonomy in wp-includes/taxonomy.php. There are several opportunities to enforce rules like this on the server side.

    I’m marking this topic “not a support question” since there’s no clear role for Media Library Assistant.

    ok, thanks. Closing topic.

    Plugin Author David Lingren


    You are welcome to continue the discussion here. I’ll be interested in any ideas other users have!

    s2member has some cross browser functions of jQuery, forcing some fields to underscore when adding, typing, pasting and before saving. Im gonna look at that script and see if it can be cloned for this matter.

    s2Member has long experiance of diffrent client activity handling…

    But for anyone who knows an exisiting hook or filter (?):

    The best solution is to hook into before save a tag filter and add a function for each template. (even if I agree tags always shuld be lowercase and Categories ucfirst. Then editors and authors understand the weight of importance and how it works togeheter, and the viewers dont get confused what is what.

    So the contex are concistant like:

    `Posted in : News, Travel
    Tagged as : adventure, skii, snow, scandinavia, sweden`

    … in my world anyway …

    Plugin Author David Lingren


    Thanks for bringing The s2Member® Framework to my attention. It looks like a powerful family of plugins and a great resource.

    This base solution seems to work fine. Just put it in the functions.php.

    function ua_pre_insert_term($term, $taxonomy ){
    	if($taxonomy == 'post_tag') $term = strtolower($term);
    	if($taxonomy == 'attachment_tag') $term = strtolower($term);
    	if($taxonomy == 'category') $term = ucfirst(strtolower($term));
    	if($taxonomy == 'attachment_category') $term = ucfirst(strtolower($term));
    	return $term;
      add_filter( 'pre_insert_term', 'ua_pre_insert_term', 99, 2);

    Closing this topic soon. as resolved.


    Using ÅÄÖ or any other characters must be using mb_strtolower(‘UTF-8’). There is no PHP function for the ucfirst(), so the easy way is to extend the PHP with a complete new function for this task. I provide one below, and the complete sooution for

    deTTA är Category ÖL = Detta är category öl
    TAG, Öl, pHOto, Icons = tag, öl, photo, icons

    The extension :

    // Extends PHP
    if (!function_exists('mb_ucfirst')) {
    	function mb_ucfirst($str, $encoding = "UTF-8", $lower_str_end = false) {
    		$first_letter = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding);
    		$str_end = "";
    		if ($lower_str_end) {
    			$str_end = mb_strtolower(mb_substr($str, 1, mb_strlen($str, $encoding), $encoding), $encoding);
    		} else {
    			$str_end = mb_substr($str, 1, mb_strlen($str, $encoding), $encoding);
    		$str = $first_letter . $str_end;
    		return $str;

    The function

    function ua_pre_insert_term($term, $taxonomy ){
    	if($taxonomy == 'post_tag') $term = mb_strtolower($term, 'UTF-8');
    	if($taxonomy == 'attachment_tag') $term = mb_strtolower($term, 'UTF-8');
    	if($taxonomy == 'category') $term = mb_ucfirst($term, 'UTF-8', true);
    	if($taxonomy == 'attachment_category') $term = mb_ucfirst($term, 'UTF-8', true);
    	return $term;
      add_filter( 'pre_insert_term', 'ua_pre_insert_term', 99, 2);
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Force tags to lowercase’ is closed to new replies.