4

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;
}

2 Answers 2

5

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);
3
  • Thanks, but maybe you know how disable that specific function? ("website", output).
    – Vitalij
    Commented Apr 30, 2015 at 12:20
  • Or second question, how disable exactly "wpseo_json_ld" action?
    – Vitalij
    Commented Apr 30, 2015 at 12:21
  • If you put an empty return of an array on wpseo_json_ld_output as a filter I think you achieve what your aiming for. The output function of the class will return nothing then. See my updated comment. Commented May 1, 2015 at 6:41
2

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

add_filter('wpseo_json_ld_output', '__return_true');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.