: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if(isset($get_meta_excerpt)){
$desc = $get_meta_excerpt;
if ( ! is_string( $desc ) || ( is_string( $desc ) && $desc === '' ) ) {
$post_content = get_post(ampforwp_get_the_ID())->post_content;
$desc = wp_trim_words( strip_shortcodes( $post_content ) , 15 );
function ampforwp_custom_yoast_meta_homepage(){
if ( 'yoast' == ampforwp_get_setting('ampforwp-seo-selection') && ampforwp_get_setting('ampforwp-seo-yoast-meta') && !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')) {
if ( class_exists('WPSEO_Options')) {
if( method_exists('WPSEO_Options', 'get_option')){
$options = WPSEO_Options::get_option( 'wpseo_social' );
if ( $options['twitter'] === true ) {
WPSEO_Twitter::get_instance();
if ( $options['opengraph'] === true ) {
$GLOBALS['wpseo_og'] = new WPSEO_OpenGraph;
do_action( 'wpseo_opengraph' );
function ampforwp_yoast_opengraph_title($title){
$new_title = ampforwp_yoast_social_title('og');
function ampforwp_yoast_twitter_title($title){
$new_title = ampforwp_yoast_social_title('twitter');
function ampforwp_yoast_social_title($type) {
//Added the opengraph for frontpage in AMP #2454
if(ampforwp_is_front_page() || ampforwp_is_blog() ){
$title = $page_id = $post = '';
$page_id = ampforwp_get_the_ID();
$title = WPSEO_Meta::get_value( 'opengraph-title', $page_id );
if( 'twitter' == $type ) {
$title = WPSEO_Meta::get_value('twitter-title',$page_id );
$title .= get_post_meta($page_id, '_yoast_wpseo_title', true);
$title = wpseo_replace_vars( $title,$post );
$title = get_the_title($page_id);
return esc_attr( get_bloginfo( 'name' ) );
function ampforwp_yoast_opengraph_desc($desc){
if ( ampforwp_yoast_social_desc('og') ){
$desc = ampforwp_yoast_social_desc('og');
function ampforwp_yoast_twitter_desc($desc){
if ( ampforwp_yoast_social_desc('twitter') ){
$desc = ampforwp_yoast_social_desc('twitter');
function ampforwp_yoast_social_desc($type) {
if(ampforwp_is_front_page() || ampforwp_is_blog()){
$page_id = ampforwp_get_the_ID();
$desc = trim( WPSEO_Meta::get_value( 'opengraph-description', $page_id ) );
if ( 'twitter' == $type ) {
$desc = trim( WPSEO_Meta::get_value( 'twitter-description', $page_id ) );
$desc = get_post_meta($page_id, '_yoast_wpseo_metadesc', true);
$desc = wp_trim_words(get_post_field('post_content', $page_id), 26);
return esc_attr( get_bloginfo( 'description' ) );
function ampforwp_custom_og_url_homepage() {
return esc_url( get_bloginfo( 'url' ) );
function ampforwp_custom_twitter_image_homepage(){
$twitter = $WPSEO_get = '';
$WPSEO_Options = WPSEO_Options::get_instance();
if( method_exists($WPSEO_Options, 'get') ){
$WPSEO_get = WPSEO_Options::get( 'twitter_site', '' );
if ( ampforwp_get_the_ID() ) {
$post_id = ampforwp_get_the_ID();
$post = get_post($post_id);
$img = WPSEO_Meta::get_value('twitter-image', $post_id );
$metatag_key = apply_filters( 'wpseo_twitter_metatag_key', 'name' );
echo '<meta ', esc_attr( $metatag_key ), '="twitter:', esc_attr( $name ), '" content="', $value, '" />', "\n";
$twitter = ltrim( trim( get_the_author_meta( 'twitter', $post->post_author ) ), '@' );
$twitter = apply_filters( 'wpseo_twitter_creator_account', $twitter );
if ( is_string( $twitter ) && $twitter !== '' ) {
echo '<meta ', esc_attr( 'name' ), '="twitter:', esc_attr( 'creator' ), '" content="','@' . esc_attr($twitter), '" />', "\n";
elseif ( $WPSEO_get !== '' && is_string( $WPSEO_get ) ) {
echo '<meta ', esc_attr( 'name' ), '="twitter:', esc_attr( 'creator'), '" content="', '@' . esc_attr(WPSEO_Options::get( 'twitter_site' )), '" />', "\n";
function ampforwp_custom_og_image_homepage() {
if ( class_exists('WPSEO_Options') ) {
$post_id = ampforwp_get_frontpage_id();
$image_url = WPSEO_Meta::get_value( 'opengraph-image', $post_id );
$image_id = WPSEO_Meta::get_value( 'opengraph-image-id', $post_id );
$image = wp_get_attachment_image_src($image_id,'full');
'width' => esc_attr(isset($image[1]) ? $image[1] : '750'),
'height' => esc_attr(isset($image[2]) ? $image[2] : '500'),
if ( method_exists($wpseo_og, 'og_tag') ) {
$wpseo_og->og_tag( 'og:image', esc_url( $image_url ) );
foreach ( $image_tags as $key => $value ) {
if ( ! empty( $value ) ) {
$wpseo_og->og_tag( 'og:image:' . $key, $value );
* @link https://github.com/ahmedkaludi/accelerated-mobile-pages/pull/761
* @since version 0.9.48 :
* 1. Removes unused code.
* 3. Keeps legacy action in place.
* 4. No longer replaces the title tag.
* 5. Instead, filters the title tag.
* 6. Therefore, it works with all SEO plugins.
* 7. Removed direct Yoast SEO compat -- It's no longer needed.
* 8. Removed unwanted spaces.
* 9. Improved performance.
* 11. Added support for CPT and attachment pages.
//26. Extending Title Tagand De-Hooking the Standard one from AMP
add_action( 'pre_amp_render_post', 'ampforwp_remove_title_tags');
function ampforwp_remove_title_tags() {
return ampforwp_replace_title_tags();
function ampforwp_replace_title_tags() {
add_filter( 'pre_get_document_title', 'ampforwp_add_custom_title_tag', 20 );
add_filter( 'wp_title', 'ampforwp_add_custom_title_tag', 10, 3 );
if(class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration') && !ampforwp_is_home() && !ampforwp_is_front_page() && !ampforwp_is_blog() ){
remove_filter( 'pre_get_document_title', 'ampforwp_add_custom_title_tag', 20 );
remove_filter( 'wp_title', 'ampforwp_add_custom_title_tag', 10, 3 );
if(class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration') && ampforwp_is_home() && !ampforwp_is_front_page() ){
remove_filter( 'pre_get_document_title', 'ampforwp_add_custom_title_tag', 20 );
remove_filter( 'wp_title', 'ampforwp_add_custom_title_tag', 10, 3 );
function ampforwp_add_custom_title_tag( $title = '', $sep = '', $seplocation = '' ) {
global $redux_builder_amp, $post;
if ( ampforwp_is_front_page() ) {
$post_id = ampforwp_get_frontpage_id();
$post = get_post($post_id);
if ( ampforwp_is_blog() ) {
$post_id = ampforwp_get_blog_details('id');
$post = get_post($post_id);
//* We can filter this later if needed:
if( class_exists('WPSEO_Options') && method_exists('WPSEO_Options', 'get') && 'yoast' == ampforwp_get_setting('ampforwp-seo-selection') && !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')) {
$separator = WPSEO_Options::get( 'separator' );
$seperator_options = WPSEO_Option_Titles::get_instance()->get_separator_options();
// This should always be set, but just to be sure.
if ( isset( $seperator_options[ $separator ] ) ) {
// Set the new replacement.
$sep = $seperator_options[ $separator ];
if( defined( 'RANK_MATH_FILE' ) && class_exists('RankMath\\Helper') && 'rank_math' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$sep = RankMath\Helper::get_settings( 'titles.title_separator' );
$sep = ' '.htmlentities( $sep, ENT_COMPAT, 'UTF-8', false ).' ';
$sep = apply_filters('ampforwp_title_seperator_type', $sep);
$title = ! empty( $post->post_title ) ? $post->post_title : $title;
$site_title = $title . $sep . get_option( 'blogname' );
} elseif ( is_archive() && $redux_builder_amp['ampforwp-archive-support'] ) {
$site_title = strip_tags( get_the_archive_title( '' ) . $sep . get_bloginfo( 'name' ) );
$site_title = get_bloginfo( 'name' ) . $sep . get_option( 'blogdescription' );
if ( ampforwp_is_front_page() ) {
//WPML Static Front Page Support for title and description with Yoast #1143
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) {
$ID = get_option( 'page_on_front' );
$ID = ampforwp_get_frontpage_id();
$site_title = get_the_title( $ID ) .' '. $sep .' '. get_option( 'blogname' );
// if ( ampforwp_is_blog() ) {
// $ID = ampforwp_get_blog_details('id');
// $site_title = get_the_title( $ID ) . $sep . get_option( 'blogname' );
$site_title = $redux_builder_amp['amp-translator-search-text'] . ' ' . get_search_query();
// Yoast SEO Title compatibility #2871
if( class_exists('WPSEO_Frontend') && ('yoast' || 1) == ampforwp_get_setting('ampforwp-seo-selection') ) {
$yoast_title = $WPSEO_Frontend = $yoast_instance = '';
if ( class_exists('Yoast\WP\SEO\Presentations\Indexable_Presentation') ) {
$yoast_instance = new \Yoast\WP\SEO\Presentations\Indexable_Presentation();
if ( !class_exists('Yoast\\WP\\SEO\\Integrations\\Front_End_Integration')) {
$WPSEO_Frontend = WPSEO_Frontend::get_instance();
$yoast_title = $WPSEO_Frontend->title($site_title);
if ( ampforwp_is_home() ) {
$yoast_title = $WPSEO_Frontend->get_title_from_options( 'title-home-wpseo' );
// For Blog pages and with Blog sub pages for example: site.com/blog/amp/page/3/
if (ampforwp_is_blog()) {
$yoast_title = $WPSEO_Frontend->get_content_title();
// Custom Front Page Title From Yoast SEO #1163
if ( ampforwp_is_front_page() || ampforwp_is_blog() && class_exists('Yoast\WP\SEO\Presentations\Indexable_Presentation')) {
$yoast_title = get_post_meta(ampforwp_get_the_ID(), '_yoast_wpseo_title', true);
$yoast_title = wpseo_replace_vars( $yoast_title,$post );
// Get info for custom front page, blog page and blog post paginated pages for v14+ #4574
if ( class_exists('Ampforwp_Yoast_Data') ){
$yoast_data = new Ampforwp_Yoast_Data;
$context = $yoast_data->get_context_for_post_id(ampforwp_get_the_ID());
if (isset($context->title)) {
$yoast_title = $context->title;
$site_title = apply_filters( 'wpseo_title', $yoast_title, $yoast_instance );
if(function_exists('genesis_theme_support') && 'genesis' == ampforwp_get_setting('ampforwp-seo-selection') ){
if(is_home() && is_front_page() && !$redux_builder_amp['amp-frontpage-select-option']){
// Determine the doctitle.
$genesis_title = genesis_get_seo_option( 'home_doctitle' ) ? genesis_get_seo_option( 'home_doctitle' ) : get_bloginfo( 'name' );
// Append site description, if necessary.
$genesis_title = genesis_get_seo_option( 'append_description_home' ) ? $genesis_title . " $sep " . get_bloginfo( 'description' ) : $genesis_title;
elseif ( is_home() && get_option( 'page_for_posts' ) && get_queried_object_id() )
$post_id = get_option( 'page_for_posts' );
if ( null !== $post_id || is_singular() ) {
if ( genesis_get_custom_field( '_genesis_title', $post_id ) ) {
$genesis_title = genesis_get_custom_field( '_genesis_title', $post_id );
elseif( is_home() && get_option( 'page_on_front' ) && $redux_builder_amp['amp-frontpage-select-option'] ){
$post_id = get_option('page_on_front');
if ( null !== $post_id || is_singular() ) {
if ( genesis_get_custom_field( '_genesis_title', $post_id ) ) {
$genesis_title = genesis_get_custom_field( '_genesis_title', $post_id );
elseif ( is_archive() ) {
if ( is_category() || is_tag() || is_tax() ) {
$term = get_queried_object();
$title_meta = get_term_meta( $term->term_id, 'doctitle', true );
$genesis_title = ! empty( $title_meta ) ? $title_meta : $title;
$user_title = get_the_author_meta( 'doctitle', (int) get_query_var( 'author' ) );
$genesis_title = $user_title ? $user_title : $title;
if ( is_post_type_archive() && genesis_has_post_type_archive_support() ) {
$genesis_title = genesis_get_cpt_option( 'doctitle' ) ? genesis_get_cpt_option( 'doctitle' ) : $title;
//$genesis_title = genesis_default_title( $title );
// genesis_default_title has been depreciated, let's do it with another method #2050
$genesis_title = genesis_get_custom_field( '_genesis_title' );
$site_title = $genesis_title;
if ( is_plugin_active('wp-seopress/seopress.php') && 'seopress' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$seopress_title = ampforwp_get_seopress_title();
$seopress_title = ampforwp_seopress_title_sanitize($seopress_title);
$site_title = $seopress_title;
if ( class_exists('All_in_One_SEO_Pack') && ampforwp_is_front_page()){
$aiseop_title = get_post_meta( $post_id, '_aioseop_title', true );
if ( !empty($aiseop_title) ) {
$site_title = $aiseop_title;
add_filter('aioseop_title', '__return_false');
if(class_exists('All_in_One_SEO_Pack') && ampforwp_is_home()){
if(!empty($aioseop_options['aiosp_home_title'])){
$aiseop_title = $aioseop_options['aiosp_home_title'];
if ( !empty($aiseop_title) ) {
$site_title = $aiseop_title;
add_filter('aioseop_title', '__return_false');
// Title From Rank Math SEO #2701 & #3358
if ( defined( 'RANK_MATH_FILE' ) && 'rank_math' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$post_id = ampforwp_get_the_ID();
if( ampforwp_is_home() || ampforwp_is_blog() ) {
$rank_math_title = RankMath\Paper\Paper::get_from_options( 'homepage_title' );
if ( ampforwp_is_front_page() || is_singular() || ampforwp_is_blog() ) {
$rank_math_title = RankMath\Post::get_meta( 'title', $post_id );
if(empty($rank_math_title)){
$rank_math_title = RankMath\Paper\Paper::get()->get_title();
$object = get_queried_object();
if( !empty($object->taxonomy) ){
$rank_math_title = RankMath\Term::get_meta( 'title', $object, $object->taxonomy );
if ( '' == $rank_math_title && !empty($object->taxonomy) ) {
$rank_math_title = RankMath\Paper\Paper::get_from_options( "tax_{$object->taxonomy}_title", $object );
if ( $rank_math_title ) {
$site_title = $rank_math_title;
//Bridge Qode SEO Compatibility #2538
if ( function_exists('qode_wp_title') && 'bridge' == ampforwp_get_setting('ampforwp-seo-selection')){
$site_title = get_post_meta($post_id, "qode_seo_title", true);
// The SEO Framework Compatibility #2670
if ( function_exists( 'the_seo_framework' ) && 'seo_framework' == ampforwp_get_setting('ampforwp-seo-selection') ) {
$tsf_title = $ampforwp_tsf = '';
$ampforwp_tsf = \the_seo_framework();
$tsf_title = $ampforwp_tsf->get_title();
$site_title = $tsf_title;
if (class_exists('WPSEO_Frontend') && $sep == 'sc-dash') {
return esc_html( convert_chars( trim( $site_title ) ) );
return esc_html( convert_chars( wptexturize( trim( $site_title ) ) ) );
// Get SEOPress Title #1589
function ampforwp_get_seopress_title(){
$seopress_title = $seopress_options = '';
$post_id = ampforwp_get_the_ID();
$post = get_post($post_id);
$seopress_get_current_cpt = get_post_type($post);
$seopress_options = get_option("seopress_titles_option_name");
if ( get_post_meta($post_id,'_seopress_titles_title',true) ) {
$seopress_title = get_post_meta($post_id,'_seopress_titles_title',true);
elseif ( isset($seopress_options['seopress_titles_single_titles'][$seopress_get_current_cpt]['title'])) {
$seopress_title = $seopress_options['seopress_titles_single_titles'][$seopress_get_current_cpt]['title'];
$seopress_title = ampforwp_seopress_title_sanitize($seopress_title);
if ( ampforwp_is_home() || ampforwp_is_blog() ) {
$seopress_titles_template_variables_array = array('%%sitetitle%%','%%tagline%%');
$seopress_titles_template_replace_array = array( get_bloginfo('name'), get_bloginfo('description') );
$seopress_title = $seopress_options['seopress_titles_home_site_title'];
$seopress_title = str_replace($seopress_titles_template_variables_array, $seopress_titles_template_replace_array, $seopress_title);
$seopress_title = get_term_meta(get_queried_object()->{'term_id'},'_seopress_titles_title',true);
// Sanitize SEOPress Title #1589
function ampforwp_seopress_title_sanitize($title){
$seopress_titles_template_variables_array = array(
'%%post_modified_date%%',
'%%_category_description%%',
'%%current_pagination%%',
'%%archive_date_month%%',
'%%wc_single_short_desc%%',
'%%wc_single_price_exc_tax%%',
$seopress_excerpt_length = 50;
$seopress_excerpt_length = apply_filters('seopress_excerpt_length',$seopress_excerpt_length);
if ($seopress_excerpt !='') {
$seopress_get_the_excerpt = wp_trim_words(esc_attr(stripslashes_deep(wp_filter_nohtml_kses(strip_shortcodes($seopress_excerpt)))), $seopress_excerpt_length);