Skip to content

Instantly share code, notes, and snippets.

View mariusghitulescu's full-sized avatar
🏠
Working from home

Marius Ghitulescu mariusghitulescu

🏠
Working from home
View GitHub Profile
@mariusghitulescu
mariusghitulescu / gist:f3fdcf91fca8604a0e76e4d2d7bf7a6d
Created September 25, 2019 13:07
Delete all yst_prominent_words terms
function delete_all_terms(){
$taxonomy_name = 'yst_prominent_words';
$terms = get_terms( array(
'taxonomy' => $taxonomy_name,
'hide_empty' => false
) );
foreach ( $terms as $term ) {
wp_delete_term($term->term_id, $taxonomy_name);
}
}
@mariusghitulescu
mariusghitulescu / gist:6e8051bbf864e015b4ec031d56e2dca3
Last active September 23, 2019 09:41
Disable JSON-LD added by Yoast SEO on post type
function disable_schema_on_post_type( $post_type ) {
if ( $post_type == 'post' ) return false;
}
add_filter( 'wpseo_json_ld_output', 'disable_schema_on_post_type', 10, 2 );
@mariusghitulescu
mariusghitulescu / gist:ec61844b01264c2fa235d38cf20609e7
Last active December 5, 2018 22:52
Custom date variable for Yoast SEO
// define the custom replacement callback, returns the date in Jan 2019 format
function get_my_date() {
return date('M Y');
}
// define the action for register yoast_variable replacments
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%my_date%%', 'get_my_date', 'advanced', 'returns the current date' );
}
@mariusghitulescu
mariusghitulescu / gist:d7f9e8f52f709ca79ce3c75370268f5a
Created September 27, 2018 14:49
Custom og:image for shop page - Yoast SEO
add_filter( 'wpseo_opengraph_image', 'change_opengraph_image_url' );
function change_opengraph_image_url($url) {
if ( is_shop() ) {
return 'https://your-image-url.jpg';
} else {
return $url;
}
}
/* Noindex all posts in a category */
add_filter("wpseo_robots", function($robots) {
if (is_single() && in_category(array(100))) {
return "noindex,follow";
}
return $robots;
});
/* Exclude One Content Type From Yoast SEO Sitemap */
function sitemap_exclude_post_type( $value, $post_type ) {
if ( $post_type == 'post_type_slug' ) return true;
}
add_filter( 'wpseo_sitemap_exclude_post_type', 'sitemap_exclude_post_type', 10, 2 );
add_filter( 'wpseo_breadcrumb_links', 'jj_wpseo_breadcrumb_links' );
function jj_wpseo_breadcrumb_links( $links ) {
//pk_print( sizeof($links) );
if( sizeof($links) > 1 ){
array_pop($links);
}
return $links;
}
@mariusghitulescu
mariusghitulescu / Entries per sitemap Yoast SEO
Last active June 12, 2018 16:29
Change the number of entries per sitemap in Yoast SEO
function max_entries_per_sitemap() {
return 1000;
}
add_filter( 'wpseo_sitemap_entries_per_page', 'max_entries_per_sitemap' );