Skip to content

Instantly share code, notes, and snippets.

View wp-seopress's full-sized avatar
😊
Coding SEOPress, best WordPress SEO plugin

Benjamin Denis wp-seopress

😊
Coding SEOPress, best WordPress SEO plugin
View GitHub Profile
@wp-seopress
wp-seopress / filter-html-sitemap-query.php
Created February 28, 2019 19:04
Filter HTML sitemap query
function sp_sitemaps_html_query($args, $cpt_key) {
//Default Query
//$args = array('posts_per_page' => 1000,'order'=> $seopress_xml_sitemap_html_order_option,'orderby' => $seopress_xml_sitemap_html_orderby_option,'post_type' => $cpt_key,'post_status' => 'publish','meta_query' => array( array( 'key' => '_seopress_robots_index', 'value' => 'yes', 'compare' => 'NOT EXISTS' ) ),'fields' => 'ids','exclude' => $seopress_xml_sitemap_html_exclude_option,'suppress_filters' => false);
if ($cpt_key =='page') { //If page post type, order page by admin menu order $args['order'] = 'ASC';
$args['orderby'] = 'menu_order';
return $args;
} else {
return $args;
}
}
@wp-seopress
wp-seopress / filter-latest-post-query-for-google-news-in-xml-index-sitemap.php
Created February 28, 2019 19:05
Filter latest post query for Google News in XML index sitemap
function sp_sitemaps_index_gnews_query($args) {
//Default Query
//$args = array('post_type' => $seopress_xml_sitemap_news_cpt_array, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'posts_per_page' => 1, 'orderby' => 'modified', 'meta_key' => '_seopress_robots_index', 'meta_value' => 'yes', 'meta_compare' => 'NOT EXISTS', 'order' => 'DESC', 'lang' => '');
$args['post_status'] = 'pending';
return $args;
}
add_filter('seopress_sitemaps_index_gnews_query', 'sp_sitemaps_index_gnews_query');
@wp-seopress
wp-seopress / filter-latest-post-type-query-in-xml-index-sitemap.php
Last active May 22, 2019 11:05
Filter latest post type query in XML index sitemap
function sp_sitemaps_index_cpt_query($args, $cpt_key) {
//Default Query
//$args = array('post_type' => $cpt_key, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'posts_per_page' => 1, 'meta_query' => array( array( 'key' => '_seopress_robots_index', 'value' => 'yes', 'compare' => 'NOT EXISTS' ) ), 'order' => 'DESC', 'orderby' => 'modified', 'lang' => '');
$args['orderby'] = 'date';
return $args;
}
add_filter('seopress_sitemaps_index_cpt_query', 'sp_sitemaps_index_cpt_query', 10, 2);
@wp-seopress
wp-seopress / filter-locale-open-graph.php
Created February 28, 2019 19:57
Filter locale Open Graph
function sp_social_og_locale($html) {
//you can add here all your conditions as if is_page(), is_category() etc..
$html = '<meta property="og:locale" content="en_US" />';
return $html;
}
add_filter('seopress_social_og_locale', 'sp_social_og_locale');
@wp-seopress
wp-seopress / filter-logged-in-users-tracking-custom-dimension-with-google-analytics.php
Created February 28, 2019 19:59
Filter logged in users tracking custom dimension with Google Analytics
function sp_gtag_cd_logged_in_cf($html) {
return "'dimension5': 'cd_logged_in',";
}
add_filter('seopress_gtag_cd_logged_in_cf', 'sp_gtag_cd_logged_in_cf');
function sp_gtag_cd_logged_in_ev($html) {
return "gtag('event', '".__('Connected users','wp-seopress')."', {'cd_logged_in': '".wp_get_current_user()->ID."'});";
}
add_filter('seopress_gtag_cd_logged_in_ev', 'sp_gtag_cd_logged_in_ev');
@wp-seopress
wp-seopress / filter-meta-description.php
Created February 28, 2019 20:00
Filter meta description
function sp_titles_desc($html) {
//you can add here all your conditions as if is_page(), is_category() etc..
$html = 'my meta description';
return $html;
}
add_filter('seopress_titles_desc', 'sp_titles_desc');
@wp-seopress
wp-seopress / filter-meta-google-noimageindex.php
Last active November 29, 2022 14:58
Filter meta google noimageindex
function sp_titles_noimageindex($html) {
//you can add here all your conditions as if is_page(), is_category() etc..
$html = 'noimageindex';
return $html;
}
add_filter('seopress_titles_noimageindex', 'sp_titles_noimageindex');
@wp-seopress
wp-seopress / filter-meta-robots.php
Created February 28, 2019 20:02
Filter meta robots
function sp_titles_robots($html) {
//you can add here all your conditions as if is_page(), is_category() etc..
$html = '<meta name="robots" content="noindex"/>';
return $html;
}
add_filter('seopress_titles_robots', 'sp_titles_robots');
@wp-seopress
wp-seopress / filter-meta-robots-noarchive.php
Created February 28, 2019 20:03
Filter meta robots noarchive
function sp_titles_noarchive($html) {
//you can add here all your conditions as if is_page(), is_category() etc..
$html = 'noarchive';
return $html;
}
add_filter('seopress_titles_noarchive', 'sp_titles_noarchive');
@wp-seopress
wp-seopress / filter-meta-robots-nofollow.php
Created February 28, 2019 20:04
Filter meta robots nofollow
function sp_titles_nofollow($html) {
//you can add here all your conditions as if is_page(), is_category() etc..
$html = 'nofollow';
return $html;
}
add_filter('seopress_titles_nofollow', 'sp_titles_nofollow');