Jump to content

[SOLVED] Character counter for meta tags in CMS and SEO URLS


Superbegood31

Recommended Posts

  • 5 months later...

The solution for use characters counter for meta tags

 

In fields_form modules controllers

 

For meta_title

Add

'maxchar' => 70

For meta_decription

Add

'maxchar' => 160

For example : AdminCmsController.php

				array(
					'type' => 'text',
					'label' => $this->l('Meta title'),
					'name' => 'meta_title',
					'id' => 'name', // for copyMeta2friendlyURL compatibility
					'lang' => true,
					'required' => true,
					'class' => 'copyMeta2friendlyURL',
					'hint' => $this->l('Invalid characters:').' <>;=#{}',
					//'prefix' => 70,
					'maxchar' => 70
				array(
					'type' => 'text',
					'label' => $this->l('Meta description'),
					'name' => 'meta_description',
					'lang' => true,
					'hint' => $this->l('Invalid characters:').' <>;=#{}',
					'maxchar' => 160

That's all :)

Link to comment
Share on other sites

New suggestion: Add a CSS class if it is exceeded maxchar

Here is my function AddClasse

function addClasse()
{
    var maxchartitle = $('#meta_title_' + id_language + '_counter').text();
    var maxchardescription = $('#meta_description_' + id_language + '_counter').text();
    if (maxchartitle <= "0")
        {
            $('#meta_title_' + id_language + '_counter').addClass('seo-nok');
        }
    else if (maxchardescription <= "0")
        {
            $('#meta_description_' + id_language + '_counter').addClass('seo-nok');
        }
    else
        {
            $('#meta_title_' + id_language + '_counter').removeClass('seo-nok');
            $('#meta_description_' + id_language + '_counter').removeClass('seo-nok');
        }
}

But there are several problems :
- The name of the ID variable is meta_title_4_counter or name_4_counter
- When we delete characters the CSS class is removed only at position 2

 

If someone would have an idea...

 

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...