Last active
June 1, 2023 01:22
-
-
Save mihdan/7d1adf827469f4ccb385f0321f36c92a to your computer and use it in GitHub Desktop.
Меняем дату публикации записи на дату обновления записи в Yoast SEO 14 +
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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