: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
add_action('amp_post_template_head', 'ampforwp_default_og_tags', 50);
if ( ! function_exists('ampforwp_default_og_tags') ) {
function ampforwp_default_og_tags(){
if ( true == ampforwp_get_setting('ampforwp-seo-og-meta-tags') && '' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$post_id = $post = $locale = $type = $title = $site_title = $desc = $url = $pub_date = $mod_date = $image = $image_width = $image_height = '';
$post_id = ampforwp_get_the_ID();
$post = get_post($post_id);
// Catch some weird locales served out by WP that are not easily doubled up.
if ( isset( $fix_locales[ $locale ] ) ) {
$locale = $fix_locales[ $locale ];
// Convert locales like "es" to "es_ES", in case that works for the given locale (sometimes it does).
if ( strlen( $locale ) === 2 ) {
$locale = strtolower( $locale ) . '_' . strtoupper( $locale );
// These are the locales FB supports.
$valid_fb_locales = array(
'cb_IQ', // Sorani Kurdish.
'en_GB', // English (UK).
'en_PI', // English (Pirate).
'en_UD', // English (Upside Down).
'en_US', // English (US).
'es_ES', // Spanish (Spain).
'es_MX', // Spanish (Mexico).
'fr_CA', // French (Canada).
'fr_FR', // French (France).
'gx_GR', // Classical Greek.
'ht_HT', // Haitian Creole.
'ja_KS', // Japanese (Kansai).
'ku_TR', // Kurdish (Kurmanji).
'nb_NO', // Norwegian (bokmal).
'nl_BE', // Dutch (Belgie).
'nn_NO', // Norwegian (nynorsk).
'nr_ZA', // Southern Ndebele.
'ns_ZA', // Northern Sotho.
'pt_BR', // Portuguese (Brazil).
'pt_PT', // Portuguese (Portugal).
'qz_MM', // Burmese (Zawgyi).
'se_NO', // Northern Sami.
'st_ZA', // Southern Sotho.
'zh_CN', // Simplified Chinese (China).
'zh_HK', // Traditional Chinese (Hong Kong).
'zh_TW', // Traditional Chinese (Taiwan).
// Check to see if the locale is a valid FB one, if not, use en_US as a fallback.
if ( ! in_array( $locale, $valid_fb_locales, true ) ) {
$locale = strtolower( substr( $locale, 0, 2 ) ) . '_' . strtoupper( substr( $locale, 0, 2 ) );
if ( ! in_array( $locale, $valid_fb_locales, true ) ) {
$og_tags['og:locale'] = $locale;
elseif ( is_singular() ) {
// We use "object" for archives
$og_tags['og:type'] = $type;
$sep = apply_filters( 'document_title_separator', '-' );
if ( ampforwp_is_home() ) {
$site_title = get_bloginfo( 'name' ) . $sep . get_option( 'blogdescription' );
if ( is_singular() || ampforwp_is_front_page() || ampforwp_is_blog() ) {
$title = ! empty( $post->post_title ) ? $post->post_title : $title;
$site_title = $title . $sep . get_option( 'blogname' );
$site_title = strip_tags( get_the_archive_title('') . $sep . get_bloginfo( 'name' ) );
$site_title = $redux_builder_amp['amp-translator-search-text'] . ' ' . get_search_query();
$og_tags['og:title'] = $site_title;
if ( ampforwp_is_home() || ampforwp_is_blog() ) {
$desc = addslashes( strip_tags( get_bloginfo( 'description' ) ) );
$desc = addslashes( strip_tags( get_the_archive_description() ) );
if ( is_single() || is_page() ) {
$desc = get_the_excerpt();
$desc = $post->post_content;
$desc = preg_replace('/\[(.*?)\]/',' ', $desc);
$desc = addslashes( wp_trim_words( strip_tags( $desc ) , 15 ) );
$desc = addslashes( ampforwp_translation($redux_builder_amp['amp-translator-search-text'], 'You searched for:') . ' ' . get_search_query() );
if ( ampforwp_is_front_page() ) {
$desc = addslashes( wp_trim_words( strip_tags( get_post_field('post_content', $post_id) ) , 15 ) );
$og_tags['og:description'] = $desc;
$url = get_permalink( $post_id );
if ( ampforwp_is_home() || ampforwp_is_front_page() || is_archive() ) {
$current_archive_url = home_url( $wp->request );
$url = trailingslashit($current_archive_url);
$remove = '/'. AMPFORWP_AMP_QUERY_VAR;
$url = str_replace($remove, '', $url);
$query_arg_array = $wp->query_vars;
if( array_key_exists( "page" , $query_arg_array ) ) {
$page = $wp->query_vars['page'];
$url = trailingslashit( $url . '?page=' . $page);
$og_tags['og:url'] = $url;
$og_tags['og:site_name'] = get_bloginfo( 'name' );
// article:published_time
$pub_date = mysql2date( DATE_W3C, $post->post_date_gmt, false );
$og_tags['article:published_time'] = $pub_date;
$mod_date = mysql2date( DATE_W3C, $post->post_modified_gmt, false );
if ( $mod_date !== $pub_date ) {
$og_tags['article:modified_time'] = $mod_date;
$og_tags['og:updated_time'] = $mod_date;
$image = ampforwp_get_post_thumbnail('url', 'full');
$image_width = ampforwp_get_post_thumbnail('width', 'full');
$image_height = ampforwp_get_post_thumbnail('height', 'full');
$og_tags['og:image'] = $image;
$og_tags['og:image:width'] = $image_width;
$og_tags['og:image:height'] = $image_height;
foreach ( $og_tags as $property => $content ) {
echo '<meta property="', esc_attr( $property ), '" content="', esc_attr( $content ), '" />', "\n";