Skip to content

Instantly share code, notes, and snippets.

@Auke1810
Last active September 1, 2018 07:20
Show Gist options
  • Save Auke1810/9939b52131bdb2af819143798aba60f2 to your computer and use it in GitHub Desktop.
Save Auke1810/9939b52131bdb2af819143798aba60f2 to your computer and use it in GitHub Desktop.
Custom aanpassingen aan yoast seo meta robot tag en canonical tag tbv technische optimalisatie van wordpress woocommerce webshop
################# SEO Aanpassingen ###########################################
# https://gist.github.com/Auke1810/9939b52131bdb2af819143798aba60f2
##############################################################################
/**
* add_noindex_tags
* meta robots tag vullen met de juiste instelling per pagina type
* Gepagineerde pagina’s (zonder parameters) moeten index, follow zijn.
* Gepagineerde pagina’s met parameters mogen een noindex, nofollow
*/
//add_action('wp_head','add_noindex_tags', 4 );
add_filter('wpseo_robots', 'add_noindex_tags', 999);
function add_noindex_tags( $string= "" ){
global $post;
# Get page number for paginated archives.
$paged = intval( get_query_var( 'paged', false ) );
# Add noindex tag to all archive, search and 404 pages.
if( is_archive() && count($_GET) == 0 ){
// gepagineerde pagina's zonder parameters
$string= "index,follow";
//echo '<meta name="robots" content="index,follow, noodp">';
}else if( count($_GET) >= 1){
// gepagineerde pagina's met parameters || alle pagina's met parameters
$string= "noindex,nofollow";
//echo '<meta name="robots" content="noindex,nofollow">';
}else if( is_search() ){
$string= "noindex,nofollow";
//echo '<meta name="robots" content="noindex,nofollow">';
}else if( is_404() ){
$string= "noindex,nofollow";
//echo '<meta name="robots" content="noindex,nofollow">';
}else if(( is_home() || is_front_page() ) && $paged >= 2 ){
# Add noindex tag to homepage paginated pages.
$string= "noindex,follow";
//echo '<meta name="robots" content="noindex,follow">';
}
return $string;
}
/**
* remove the yoast canonical tag on archive, search and 404 pages.
* Pagina’s met filter of sorteeropties in de URL moeten geen canonical hebben
* .
*/
add_filter( 'wpseo_canonical', 'wpseo_canonical_exclude' );
function wpseo_canonical_exclude( $canonical ) {
global $post;
if( count($_GET) >= 1){
// gepagineerde pagina's met parameters || alle pagina's met parameters
$canonical = false;
remove_action('wp_head', 'rel_canonical');
}
if( is_search() || is_404() ){
$canonical = false;
remove_action('wp_head', 'rel_canonical');
}
return $canonical;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment