X

Excluir categorías de RSS Feed con functions.php

Snippets by IsItWP

¿Estás buscando una forma de eliminar categorías del feed RSS usando el archivo functions.php de tu tema? Si bien es probable que haya un plugin para esto, hemos creado un fragmento de código rápido que puede utilizar para excluir categorías del feed RSS con functions.php 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. A continuación, añada los ID de las categorías que desea excluir en la línea 3 (actualmente están configurados como 20, 21 y 22). Asegúrese de utilizar un signo menos, “-“, antes del ID de la categoría.

function exclude_cat_wps($query) {
    if ($query->is_feed) {
        $query->set('cat','-20,-21,-22');
    }
    return $query;
}
add_filter('pre_get_posts','exclude_cat_wps');

Nota: Si es la primera vez que añade fragmentos de código en WordPress, consulte nuestra guía sobre cómo copiar / pegar correctamente fragmentos de código en WordPress, para no romper accidentalmente su sitio.

Si le ha gustado este fragmento de código, por favor considere revisar nuestros otros artículos en el sitio como: Cómo crear un sitio de membresía de WordPress y 9 mejores plugins de gestión de anuncios de WordPress para aumentar los ingresos.

Comentarios   Deja una respuesta

  1. I wonder if you can help, even though I have followed other instructions before I landed here.

    I have copied my blog so it is on 2 different pages on my website. On page 182 I want specific blog categories to show. On page 195 I want the rest of the categories to show.

    I created a child theme. Here I copied (through file manager) page.php and renamed one “page-182.php” and another “page-195.php”.

    In each page file I inserted a code which should include the specific categories for each page and saved it.

    But all categories show on both pages still, so nothing has changed.

    What am I doing wrong?

    This is page-195.php including the code:

    <div id=”primary” >

    $args = array(‘category__in’=>array( 90, 92, 91 ),);
    // The Query
    $the_query = new WP_Query( $args );

    // The Loop
    if ( $the_query->have_posts() ) {
    echo ‘’;
    while ( $the_query->have_posts() ) {
    $the_query->the_post();
    echo ‘’ . get_the_title() . ‘’;
    echo ‘’ . get_the_content() . ‘’;
    }
    echo ‘’;
    } else {
    // no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    —-this part is the code only:
    $args = array(‘category__in’=>array( 90, 92, 91 ),);
    // The Query
    $the_query = new WP_Query( $args );

    // The Loop
    if ( $the_query->have_posts() ) {
    echo ‘’;
    while ( $the_query->have_posts() ) {
    $the_query->the_post();
    echo ‘’ . get_the_title() . ‘’;
    echo ‘’ . get_the_content() . ‘’;
    }
    echo ‘’;
    } else {
    // no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    I hope you can see where I am going wrong. I am new and do not understand the code. Just google and youtubed my way through this.

    Thank you 🙂

    1. It appears that the PHP code may not be properly wrapped with PHP tags. You may also want to check out this snippet: https://www.isitwp.com/list-recent-posts-from-a-single-category/

  2. thank

  3. Does this take some time to update? I followed these instructions exactly but the category’s posts are still showing up in the RSS2.0 feed.

    1. Hi Zachary
      No this should work right away, do you have any other code that may cause this to have problems? RSS related plugins,

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!