X

Mejor SEO Eliminar automáticamente las palabras cortas de la URL

Snippets by IsItWP

¿Estás buscando una forma de eliminar las palabras vacías de tus URLs? Si bien es probable que haya un plugin para esto, hemos creado un fragmento de código rápido que puede utilizar para mejorar el SEO mediante la eliminación automática de palabras cortas de URL en WordPress.

Instrucciones:

Todo lo que tienes que hacer es añadir este código al archivo functions.php de tu tema o en un plugin específico del sitio:

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

Nota: Si es la primera vez que añades fragmentos de código en WordPress, consulta nuestra guía sobre cómo añadir correctamente fragmentos de código en WordPress, para no romper accidentalmente tu sitio.

Si te ha gustado este fragmento de código, por favor, considere la posibilidad de revisar nuestros otros artículos en el sitio como: 11 mejores plugins de WordPress para concursos y cómo configurar el seguimiento de autores en WordPress con Google Analytics.

Comentarios   Deja una respuesta

  1. Hello friend,
    How to remove only certain words from slug?
    Thanks a lot

    1. You could try using this, replaceing “word” with the word you which to remove:

      if ($word === “word”) {
      unset($slug[$k]);
      }

  2. Boost Your WordPress SEO with Short URLs - WPMU.org septiembre 6, 2013 en 5:50 pm

    […] to Kevin Chard for these awesome […]

  3. 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/

  4. Peerland Fire Alarm agosto 5, 2011 en 12:11 pm

    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.

    1. 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/

  5. Alexandre M. Cajaty julio 14, 2011 en 5:09 pm

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

    1. Great snippet Alexandre. Email me so I can  set you up as an author for the snippet.
      http://wpsnipp.com/index.php/contact/

  6. Trieu Quang Khanh junio 24, 2011 en 3:29 am

    this is bad for vietnamese

    1. 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. 

      1. Trieuquangkhanh julio 19, 2011 en 7:12 am

        Great.

  7. 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.

    1. 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.

  8. Do you think this is important for SEO? Why?

    Thanks
    Teo

    1. 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.

Añadir un comentario

Nos alegra que haya decidido dejar un comentario. Tenga en cuenta que todos los comentarios se moderan de acuerdo con nuestra política de privacidad , y que todos los enlaces son nofollow. NO utilice palabras clave en el campo del nombre. Tengamos una conversación personal y significativa.

WordPress Launch Checklist

La lista definitiva para lanzar WordPress

Hemos recopilado todos los elementos esenciales de la lista de comprobación para el lanzamiento de su próximo sitio web de WordPress en un práctico ebook.
Sí, envíeme el ¡gratuito!