Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove action from yoast plugin

Tags:

wordpress

I want remove json-ld website microdata, and I think I must disable action in the class WPSEO_JSON_LD

Action:

add_action( 'wpseo_json_ld', array( $this, 'website' ), 10 );

Changes in my functions.php:

remove_action( 'wpseo_json_ld', array( 'WPSEO_JSON_LD', 'website' ), 10 );

What I am doing wrong?

Solution:

add_filter( 'wpseo_json_ld_output', 'swp_remove_jsonld_yoast', 10, 2 );

function swp_remove_jsonld_yoast($data, $context){

    if($data['@type'] == 'WebSite'){
        $data = false;
    }

    return $data;
}
like image 927
Vitalij Avatar asked Mar 16 '23 05:03

Vitalij


2 Answers

You can better use a filter to clear the output by that function I think. There are filters for wpseo_json_ld_output.

function remove_json_ld_output( $data ) {
 $data = array();

 return $data;
}

add_filter('wpseo_json_ld_output', 'remove_json_ld_output', 10, 1);
like image 116
Niels van Renselaar Avatar answered Mar 25 '23 03:03

Niels van Renselaar


I got it working by adding this snippet into my functions.php file

add_filter('wpseo_json_ld_output', '__return_true');
like image 40
Jake Avatar answered Mar 25 '23 03:03

Jake