Vous cherchez un moyen de supprimer les mots courts de vos URLs ? Bien qu’il existe probablement un plugin pour cela, nous avons créé un extrait de code rapide que vous pouvez utiliser pour améliorer le référencement en supprimant automatiquement les mots courts des URL dans WordPress.
Instructions:
Tout ce que vous avez à faire est d’ajouter ce code dans le fichier functions.php de votre thème ou dans un plugin spécifique à votre site:
add_filter('sanitize_title', 'remove_short_words'); function remove_short_words($slug) { if (!is_admin()) return $slug; $slug = explode('-', $slug); foreach ($slug as $k => $word) { if (strlen($word) < 3) { unset($slug[$k]); } } return implode('-', $slug); }
Note : Si c’est la première fois que vous ajoutez des extraits de code dans WordPress, veuillez consulter notre guide sur la façon d’ajouter correctement des extraits de code dans WordPress, afin de ne pas casser accidentellement votre site.
Si vous avez aimé cet extrait de code, n’hésitez pas à consulter nos autres articles sur le site comme : 11 meilleurs plugins de quiz WordPress et comment configurer le suivi des auteurs sur WordPress avec Google Analytics.
Hello friend,
How to remove only certain words from slug?
Thanks a lot
You could try using this, replaceing “word” with the word you which to remove:
if ($word === “word”) {
unset($slug[$k]);
}
[…] to Kevin Chard for these awesome […]
Well the idea is that if you remove words like “The, and, but, is, it,” etc, since they don’t have any real SEO value. However the above snippet was updated to remove only a list of words rather then all words with 3 characters or less.
http://wpsnipp.com/index.php/functions-php/better-seo-automatically-remove-stop-words-from-slug/
I am a newbie in SEO field recently I was told to collect some new information and guess what,I gave them your idea and they really liked it.So in other words your advice save me.Thanks man!Really nice one.People please try this.
You should take a look at this snippet. This is an updated version of the snippet above.
http://wpsnipp.com/index.php/functions-php/better-seo-automatically-remove-stop-words-from-slug/
Congratulations for the post!
I adapted your code with a list of negative words separated by commas.
Hug!****add_filter(‘sanitize_title’, ‘remove_short_words’);function remove_short_words($slug) { if (!is_admin()) return $slug; $slug = explode(‘-‘, $slug); foreach ($slug as $k => $word) { //keywords false $keys_false = ‘a,ao,aos,as,ate,da,de,do,das,dos,dum,duma,e,em,es,na,no,nas,nos,num,numa,o,os,que,um,uma’; $keys = explode(‘,’, $keys_false); foreach ($keys as $l => $wordfalse) { if ($word==$wordfalse) { unset($slug[$k]); } } } return implode(‘-‘, $slug);}
Great snippet Alexandre. Email me so I can set you up as an author for the snippet.
http://wpsnipp.com/index.php/contact/
this is bad for vietnamese
This is true Trieu Quang Khan, I’m going to publish an updated version that will let users define words that will get removed from the slug.
Great.
Does it exclude 3 letter words? The write up implies it does by including the words but and and, but the screenshot shows seo still there in the URL? Presume it is the condition in line 6 that needs changing. Could removing 3 letter words be too drastic as it could remove words required for the URL to make sense? who, cup, bar, win, end, seo(!) etc.. (which could then have a negative rather than positive effect on seo?)
Cheers.
David.
This is true, one modification I could do to this snippet would be to create a list of words that it should remove. This way it would not remove words that may be important to the SEO of the site.
Do you think this is important for SEO? Why?
Thanks
Teo
The more words you have in the URL Google will weight what could be important words less. Since the if, and, the, is, are, etc are not as important as other words this script will remove them.