Includere una pagina tra i feed RSS
Il filtro verifica se i posti sono presenti post di un feed, e se ci sono , va a modificare la query per includere sia post e pagine.
function feedFilter($query) { if ($query->is_feed) { $query->set('post_type','any'); } return $query; } add_filter('pre_get_posts','feedFilter');
Se si vogliono visualizzare solo le pagine, allora si potrebbe cambiare la parola ‘any’ su ‘page’ (o con il nome di un qualsiasi post personalizzatao che si è creati). E’ possibile selezionare solo i feed delle pagine di livello più alto con il codice seguente:
function feedFilter($query) { if ($query->is_feed) { $query->set('post_type','any'); $query->set('post_parent','0'); } return $query; } add_filter('pre_get_posts','feedFilter');
Aggiungere Thumbnails ai feed RSS
function feedFilter($query) { if ($query->is_feed) { add_filter('the_content', 'feedContentFilter'); } return $query; } add_filter('pre_get_posts','feedFilter'); function feedContentFilter($content) { $thumbId = get_post_thumbnail_id(); if($thumbId) { $img = wp_get_attachment_image_src($thumbId); $image = '<img align="left" src="'. $img[0] .'" alt="" width="'. $img[1] .'" height="'. $img[2] .'" />'; echo $image; } return $content; }
Escludere i post con un certo Tag
Se vogliamo escludere dai feed RSS tutti i posti con il tag numero 29 e possibile utilizzare il seguente codice:
function feedFilter($query) { if ($query->is_feed) { $tags = array('29'); $query->set('tag__not_in', $tags); } return $query; } add_filter('pre_get_posts','feedFilter');
Filtrare i feed RSS di una certa categoria
E’ possibile filtrare i feed rss in base al nome della categoria, in questa caso: “blog”
function feedFilter($query) { if ($query->is_feed) { $query->set('category_name', 'blog'); } return $query; } add_filter('pre_get_posts','feedFilter');
inoltre è possibile escludere i post di una certa categoria con
$query->set('cat', '-45');
Aggiungere contenuto alla fine al Feed RSS di ogni post
Nel caso seguente sarà aggiunta qualcosa tipo: “Thanks for reading, check out Your Blog name for more WordPress news!”
function feedFilter($query) { if ($query->is_feed) { add_filter('the_content','feedContentFilter'); } return $query; } add_filter('pre_get_posts','feedFilter'); function feedContentFilter($content) { $content .= '<p>Thanks for reading, check out <a href="'. get_bloginfo('url') .'">'. get_bloginfo('name') .'</a> for more WordPress news!</p>'; return $content; }