Jump to content

[RÉSOLU] Compteur de caractères pour les balises meta dans CMS et SEO & URL


Recommended Posts

Bonjour,

Prestashop 1.6 intègre un compteur de caractères pour les balises méta dans l'onglet SEO des fiches produits.

Serait-il possible d'inclure cette fonction dans toutes les pages où se trouve des balises méta ?

Ne s'agirait-il pas de la fonction countDown dans le template input_text_lang.tpl ?

Merci.

Edited by SWITCHBOARD (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...
  • 5 months later...

La solution pour utiliser le compteur de caractères pour vos balises méta

 

Dans les fields_form des controllers de vos modules

 

Pour meta_title

Ajouter

'maxchar' => 70

 

Pour meta_decription

Ajouter

'maxchar' => 160

 

Par exemple : 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:').' <>;=#{}',
                    'maxchar' => 70
                array(
                    'type' => 'text',
                    'label' => $this->l('Meta description'),
                    'name' => 'meta_description',
                    'lang' => true,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}',
                    'maxchar' => 160

C'est tout :)

Link to comment
Share on other sites

Une autre petite idée : Ajouter une class CSS pour mettre en évidence lorsque l'on dépasse le max-char

 

Mais mon code ne fonctionne pas

Dans themes\default\template\helpers\form\form.tpl

function addClasse() {
 var seochar = $('#meta_title_4_counter').val().length;
  if (seochar < 0)
  {
   $('#meta_title_4_counter').addClass('seo-nok');
  }
}

et j'ai ajouté addClasse(); au keyup

 

Si quelqu'un a une idée...

Link to comment
Share on other sites

J'avance mais le fonctionnement n'est pas optimal

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');
		}
}

Si on dépasse le maxchar, le css s'applique immédiatement.

 

Mais si on revient en arrière et que le maxchar est inférieur ou égal alors le css ne revient pas normalement...

 

Cas concret :

On rentre du texte et on arrive à -1 la classe seo-nok s'ajoute

On supprime du texte et on arrive à 0 la classe seo-nok ne s'enlève pas (elle s'enlève à 2)

Edited by SWITCHBOARD (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

La solution pour utiliser le compteur de caractères pour vos balises méta

 

Dans les fields_form des controllers de vos modules

 

Pour meta_title

Ajouter

'maxchar' => 70

 

Pour meta_decription

Ajouter

'maxchar' => 160

 

Par exemple : 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:').' <>;=#{}',
                    'maxchar' => 70
                array(
                    'type' => 'text',
                    'label' => $this->l('Meta description'),
                    'name' => 'meta_description',
                    'lang' => true,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}',
                    'maxchar' => 160

C'est tout :)

 

Merci !!!

J'ai cherché cette fonction pendant des heures, et n'aurai jamais pensé que la solution serait aussi simple !

Encore merci d'avoir partagé ta solution !

Link to comment
Share on other sites

Bonjour,

 

Par exemple : AdminCmsController.php

Dans le fields_form (ligne 110)

Ajouter la varaible max-char

 

Meta_title

                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:').' <>;=#{}',
                    'maxchar' => 70 

                   

Meta_description

                array(
                    'type' => 'text',
                    'label' => $this->l('Meta description'),
                    'name' => 'meta_description',
                    'lang' => true,
                    'hint' => $this->l('Invalid characters:').' <>;=#{}',
                    'maxchar' => 160
  • Like 1
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...