Last active
July 19, 2021 21:40
-
-
Save xlawok/c53534ef89c0f9da6b50f06eec429593 to your computer and use it in GitHub Desktop.
WP SEO YOAST and ALL IN ONE
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
/ALL IN ONE title | |
add_filter( 'aioseop_title', 'change_wordpress_seo_title' ); | |
function change_wordpress_seo_title( $title ){ | |
$term = get_queried_object(); | |
if(!empty($term)&&$term->taxonomy=='category'){ | |
if($term->term_id==62) $title="Artykuły BHP Wrocław - Hurtownia Online ".get_bloginfo( 'name' ); | |
} | |
return $title; | |
} | |
//another one for All in one seo | |
add_filter( 'aioseop_title', 'change_wordpress_seo_title' ); | |
function change_wordpress_seo_title( $title ){ | |
$term = get_queried_object(); | |
if(!empty($term)&&$term->taxonomy=='product_cat'&&$term->term_id==128){ | |
$title="Czujniki dymu - czujki dymowe - ".get_bloginfo( 'name' ); | |
} | |
else{ | |
$title = ucfirst(mb_strtolower($title, 'UTF-8')); | |
$part = get_bloginfo( 'name' ); | |
$title = str_replace( mb_strtolower($part, 'UTF-8'), $part, $title); | |
} | |
return $title; | |
} | |
//YOAST | |
add_action('init', function() { | |
add_filter( 'wpseo_canonical', '__return_false', 10 ); | |
add_filter("wpseo_robots", function($robots) { | |
$url = $_SERVER['REQUEST_URI']; | |
if (strpos($url,'?') !== false||strpos($url,'/page/') !== false) { | |
return "noindex, follow"; | |
} | |
else | |
return $robots; | |
}); | |
add_filter('wpseo_title', function($title) { | |
$subpage = get_query_var('sub'); | |
$site_title=get_bloginfo( 'name' ); | |
if(is_tax('location')) { | |
$term = get_queried_object(); | |
$term_name=$term->name; | |
if($subpage === 'znajdz-mieszkanie'){ | |
$title = "Znajdź mieszkanie - ".$term_name." - ".$site_title; | |
} | |
else if($subpage === 'lokalizacja'){ | |
$title = "Lokalizacja - ".$term_name." - ".$site_title; | |
} | |
else if($subpage === 'relacja-z-budowy'){ | |
$title = "Relacja z budowy - ".$term_name." - ".$site_title; | |
} | |
else if($subpage === 'pod-klucz'){ | |
$title = "Mieszkanie Pod Klucz - ".$term_name." - ".$site_title; | |
} | |
} | |
return $title; | |
}); | |
}); | |
yoast change canonical | |
add_action('init', function() { | |
$url = $_SERVER['REQUEST_URI']; | |
if (strpos($url,'sklep/page/') !== false) | |
{ | |
add_filter( 'wpseo_canonical', function($canonical){ | |
$canonical="https://example.pl/sklep/"; | |
return $canonical; | |
}, 10 ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment