Last active
January 11, 2021 12:59
-
-
Save teles/0d31b4b59637e0a84138493edc95780d to your computer and use it in GitHub Desktop.
Feed Google News para WordPress. Esse código adiciona um novo endpoint de feed no seu blog WordPress. Esse endpoint é cadastrado no functions.php com a url /feed/google-news e /rss/google-news. Valide seu feed via Google Search Console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Custom RSS Feed following Google News specification | |
// No Products Allowed in This Feed | |
add_action('init', 'googleNewsRSS'); | |
function googleNewsRSS(){ | |
add_feed('google-news', 'googleNewsRSSFunc'); | |
} | |
function googleNewsRSSFunc(){ | |
get_template_part('rss', 'google-news'); | |
} | |
function the_content_feed_for_google_news($content) { | |
return $content; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: Custom RSS Template - Google News | |
*/ | |
$query_posts_args = array( | |
'posts_per_page' => 14, | |
'orderby' => 'modified', | |
'order' => 'DESC' | |
); | |
$posts = query_posts($query_posts_args); | |
header('Content-Type: '.feed_content_type('rss-http').'; charset='.get_option('blog_charset'), true); | |
echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; | |
?> | |
<rss version="2.0" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" | |
xmlns:admin="http://webns.net/mvcb/" | |
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:content="http://purl.org/rss/1.0/modules/content/"> | |
<channel> | |
<title><?php bloginfo_rss('name'); ?></title> | |
<link><?php bloginfo_rss('url') ?></link> | |
<description><?php bloginfo_rss('description') ?></description> | |
<lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate> | |
<dc:language>pt-BR</dc:language> | |
<dc:date><?php echo mysql2date('Y-m-d\TH:i:s-00:00', get_lastpostmodified('GMT'), false); ?></dc:date> | |
<sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod> | |
<sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency> | |
<?php while(have_posts()) : the_post(); ?> | |
<item> | |
<title><?php the_title_rss(); ?></title> | |
<link><?php the_permalink_rss(); ?></link> | |
<comments><?php comments_link_feed(); ?></comments> | |
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate> | |
<dc:creator><![CDATA[<?php the_author(); ?>]]></dc:creator> | |
<?php the_category_rss(); ?> | |
<guid isPermaLink="false"><?php the_guid(); ?></guid> | |
<content:encoded><![CDATA[<?php echo the_content_feed_for_google_news(get_the_content_feed()) ?>]]></content:encoded> | |
<?php rss_enclosure(); ?> | |
</item> | |
<?php endwhile; ?> | |
</channel> | |
</rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment