• Resolved Tobys

    (@tobys)


    Hi
    I am using an api to fetch data to some specific posts which have their own theme template. Since the posts are not edited in WP when the data is, I want to use my theme to set the following properties:

    1) The meta property “article:modified_time”, example:
    <meta property=”article:modified_time” content=”2020-11-10T13:00:48+00:00″ />

    2) The https://schema.org graph content:
    “dateModified”: “2020-11-10T13:00:48+00:00”

    How can I do this programmatically? I cannot find any filters to change this.

    Help appreciated, thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support devnihil

    (@devnihil)

    @tobys Unfortunately we can’t offer support on custom code. Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code, we cannot advise you on how to make such changes. Maybe someone watching these forums can assist you further, but if your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview.

    Thread Starter Tobys

    (@tobys)

    For anyone curious, this is the solution I came up with. If anyone can spot weaknesses or a better solution, then please let me know.

    <?php
    use Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter;
    
    function remove_wp_seo_presenters( $filter ) {
    
    	if (($key = array_search('Yoast\WP\SEO\Presenters\Open_Graph\Article_Modified_Time_Presenter', $filter)) !== false) {
    		unset($filter[$key]);
    	}
    
    	return $filter;
    }
    add_filter( 'wpseo_frontend_presenter_classes', 'remove_wp_seo_presenters' );
    
    class Custom_Presenter extends Abstract_Indexable_Presenter {
    
    	public $property;
    	public $content;
    
    	function __construct($property, $content) {
    		$this->property = $property;
    		$this->content = $content;
    	}
    
    	public function present() {
    		return '<meta property="' . esc_attr( $this->property ) . '" content="' . esc_attr( $this->content ) . '" />';
    	}
    
    	public function get() {
    		return null;
    	}
    }
    
    function add_custom_presenter( $presenters ) {
    
    	$modified_time = new Custom_Presenter("article:modified_time", "2020-11-10");
    
    	$presenters[] = $modified_time;
    
    	return $presenters;
    }
    add_filter( 'wpseo_frontend_presenters', 'add_custom_presenter' );
    ?>
    <?php
    use Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter;
    
    function remove_wp_seo_presenters( $filter ) {
    
    	if (($key = array_search('Yoast\WP\SEO\Presenters\Open_Graph\Article_Modified_Time_Presenter', $filter)) !== false) {
    		unset($filter[$key]);
    	}
    
    	return $filter;
    }
    add_filter( 'wpseo_frontend_presenter_classes', 'remove_wp_seo_presenters' );
    
    class Custom_Presenter extends Abstract_Indexable_Presenter {
    
    	public $property;
    	public $content;
    
    	function __construct($property, $content) {
    		$this->property = $property;
    		$this->content = $content;
    	}
    
    	public function present() {
    		return '<meta property="' . esc_attr( $this->property ) . '" content="' . esc_attr( $this->content ) . '" />';
    	}
    
    	public function get() {
    		return null;
    	}
    }
    https://casinoshunter.com/online-casinos/roulette/
    function add_custom_presenter( $presenters ) {
    
    	$modified_time = new Custom_Presenter("article:modified_time", "2020-11-10");
    
    	$presenters[] = $modified_time;
    
    	return $presenters;
    }
    add_filter( 'wpseo_frontend_presenters', 'add_custom_presenter' );
    ?>
    Expand
    

    Perfect

    • This reply was modified 3 years, 10 months ago by jordanmemphis.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change meta with code – article:modified_time and datePublished’ is closed to new replies.