• Resolved Lucas Martins

    (@lucasms)


    I used to have this piece of code to remove the published time from the opengraph (and meta tags). But it no longer works.

    function remove_publish_date() {
        global $wpseo_og;
        remove_action( 'wpseo_opengraph', array( $wpseo_og, 'publish_date' ), 19);
    }
    add_action( 'wpseo_opengraph', 'remove_publish_date' );

    in https://developer.yoast.com/blog/yoast-seo-14-0-adding-metadata/ it says to use Abstract_Indexable_Presenter do add more meta tags, but nothing how to remove or edit opengraph data.

    It is not possible anymore?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Lucas Martins

    (@lucasms)

    Found a way to remove the tags from opengraph:

    function add_my_custom_presenter( $presenters ) {
    	
    
    	$presenters_to_remove = array('Article_Published_Time_Presenter', 'Article_Modified_Time_Presenter');
    	for($x=1; $x<=sizeof($presenters); $x++) {
    		
    		$classname = substr(get_class($presenters[$x]), strrpos(get_class($presenters[$x]), "\\")+1);
    	
    		if(in_array($classname, $presenters_to_remove)) {
    			
    			unset($presenters[$x]);
    		}
    	}
    		
    	return $presenters;
    }
    
    add_filter( 'wpseo_frontend_presenters', 'add_my_custom_presenter' );

    but this data is still showing in the jd+json schema graph.

    edit 2: got that fixed too

    add_filter( 'wpseo_schema_article', 'remove_date_from_schema_graph');
    add_filter( 'wpseo_schema_webpage', 'remove_date_from_schema_graph');
    
    function remove_date_from_schema_graph( $array ) {
    		unset($array['datePublished']);
    		unset($array['dateModified']);
        return $array;
    }

    Thanks Lucas you saved my day !

    function add_my_custom_presenter( $presenters ) {
        
    	$presenters_to_remove = ['Locale_Presenter'];
    	for($x=1; $x<=sizeof($presenters); $x++) {
    		
    		$classname = substr(get_class($presenters[$x]), strrpos(get_class($presenters[$x]), "\\")+1);
    	
    		if(in_array($classname, $presenters_to_remove)) {
    			
    			unset($presenters[$x]);
    		}
    	}
      
    	return $presenters;
    }
    
    add_filter( 'wpseo_frontend_presenters', 'add_my_custom_presenter' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wpseo_opengraph deprecated. How to remove things from OpenGraph now?’ is closed to new replies.