Skip to content

Instantly share code, notes, and snippets.

@mihdan
Last active June 1, 2023 01:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihdan/7d1adf827469f4ccb385f0321f36c92a to your computer and use it in GitHub Desktop.
Save mihdan/7d1adf827469f4ccb385f0321f36c92a to your computer and use it in GitHub Desktop.
Меняем дату публикации записи на дату обновления записи в Yoast SEO 14 +
<?php
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Tag_Presenter;
/**
* Debug microdata.
*/
add_filter( 'yoast_seo_development_mode', '__return_true' );
/**
* Change datePublished to dateModified in microdata
*/
add_filter(
'wpseo_schema_webpage',
function ( $data ) {
$data['datePublished'] = get_the_modified_date( 'c' );
return $data;
}
);
/**
* Disable default tag `article:published_time`.
*/
add_filter(
'wpseo_frontend_presenter_classes',
function ( $filter ) {
if ( ( $key = array_search('Yoast\WP\SEO\Presenters\Open_Graph\Article_Published_Time_Presenter', $filter ) ) !== false ) {
unset( $filter[ $key ] );
}
return $filter;
}
);
/**
* Register custom presenter class for Yoast.
*/
add_filter(
'wpseo_frontend_presenters',
function ( $presenters ) {
$presenters[] = new My_Custom_Presenter();
return $presenters;
}
);
/**
* Register our meta tag `article:published_time`.
*/
add_action(
'plugins_loaded',
function() {
/**
* Adds a custom my:property.
*/
class My_Custom_Presenter extends Abstract_Indexable_Tag_Presenter {
/**
* The tag format including placeholders.
*
* @var string
*/
protected $tag_format = '<meta property="article:published_time" content="%s" />';
/**
* Returns the value of our new tag.
*
* @return string The value of our meta tag.
*/
public function get() {
return $this->presentation->open_graph_article_modified_time;
}
}
}
);
// eol.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment