Skip to content

Instantly share code, notes, and snippets.

@sybrew
Created June 10, 2023 22:53
Show Gist options
  • Save sybrew/38f013d5fa5ab7643a846312ac90db96 to your computer and use it in GitHub Desktop.
Save sybrew/38f013d5fa5ab7643a846312ac90db96 to your computer and use it in GitHub Desktop.
Polylang Post Type Archive overwrite for TSF
<?php
// Request: https://wordpress.org/support/topic/the-seo-framework-polylang-post-type-archive-settings-not-translatable/
add_filter( 'the_seo_framework_post_type_archive_meta', 'my_custom_seo_framework_post_type_archive_meta', 10, 2 );
/**
* Filters The SEO Framework post type archive meta based on Polylang's language.
*
* @param array $meta The current post type archive meta : {
* 'doctitle' => string
* 'title_no_blog_name' => int
* 'description' => string
* 'og_title' => string
* 'og_description' => string
* 'tw_title' => string
* 'tw_description' => string
* 'social_image_url' => string
* 'social_image_id' => int
* 'canonical' => string
* 'noindex' => int
* 'nofollow' => int
* 'noarchive' => int
* 'redirect' => string
* }
* @param string $post_type The current post type.
* @return array $meta The post type archive metadata for TSF.
*/
function my_custom_seo_framework_post_type_archive_meta( $meta, $post_type ) {
// Bail if Polylang's language setting isn't available.
if ( ! function_exists( 'pll_current_language' ) ) return $meta;
// Bail if 'news' isn't the post type.
if ( 'news' !== $post_type ) return $meta;
switch ( pll_current_language() ) {
case 'en':
$meta['doctitle'] = "English Document Title";
$meta['description'] = "English Description";
$meta['og_title'] = "English Open Graph Title";
$meta['og_description'] = "English Open Graph Description";
$meta['tw_title'] = "English Twitter Title";
$meta['tw_description'] = "English Twitter Description";
break;
case 'de':
$meta['doctitle'] = "German Document Title";
$meta['description'] = "German Description";
$meta['og_title'] = "German Open Graph Title";
$meta['og_description'] = "German Open Graph Description";
$meta['tw_title'] = "German Twitter Title";
$meta['tw_description'] = "German Twitter Description";
break;
}
return $meta;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment