2 added 547 characters in body
source | link

Hi I'm having problems with the the_title filter here's the code that I have:

function zen_title_filter($title){

    if(is_singular()){
        if(!empty($_GET['asin'])){
            if($title == 'Product Details Page' || $title == 'Compare Products Page'){
                $title = zen_get_titles();

            }

        }

    }

    return $title;
}

add_filter('the_title', 'zen_title_filter');

As you can see this filter updates both the menu title for the product details page and compare products page. But the behavior that I'm expecting is that it should only update the title of the post itself but not the menu title which in this case is also the same as the post title. Any ideas?

enter image description here

UPDATE

I'm actually generating the page on the fly. Using a page as the template. So the post id is the id of the page. What I'm doing is adding filter to the content and completely replace the content of the page using the new content:

add_filter('the_content', function($content){
  if(is_page('compare')){
   $asin = esc_attr($_GET['asin']);
   $data = get_data($asin);
   $smarty->assign('item_data', $data);
   $content = $smarty->fetch('file.tpl');
  }
  return $content;
});

Hi I'm having problems with the the_title filter here's the code that I have:

function zen_title_filter($title){

    if(is_singular()){
        if(!empty($_GET['asin'])){
            if($title == 'Product Details Page' || $title == 'Compare Products Page'){
                $title = zen_get_titles();

            }

        }

    }

    return $title;
}

add_filter('the_title', 'zen_title_filter');

As you can see this filter updates both the menu title for the product details page and compare products page. But the behavior that I'm expecting is that it should only update the title of the post itself but not the menu title which in this case is also the same as the post title. Any ideas?

enter image description here

Hi I'm having problems with the the_title filter here's the code that I have:

function zen_title_filter($title){

    if(is_singular()){
        if(!empty($_GET['asin'])){
            if($title == 'Product Details Page' || $title == 'Compare Products Page'){
                $title = zen_get_titles();

            }

        }

    }

    return $title;
}

add_filter('the_title', 'zen_title_filter');

As you can see this filter updates both the menu title for the product details page and compare products page. But the behavior that I'm expecting is that it should only update the title of the post itself but not the menu title which in this case is also the same as the post title. Any ideas?

enter image description here

UPDATE

I'm actually generating the page on the fly. Using a page as the template. So the post id is the id of the page. What I'm doing is adding filter to the content and completely replace the content of the page using the new content:

add_filter('the_content', function($content){
  if(is_page('compare')){
   $asin = esc_attr($_GET['asin']);
   $data = get_data($asin);
   $smarty->assign('item_data', $data);
   $content = $smarty->fetch('file.tpl');
  }
  return $content;
});
1
source | link

Adding filter to the title without affecting the menu title

Hi I'm having problems with the the_title filter here's the code that I have:

function zen_title_filter($title){

    if(is_singular()){
        if(!empty($_GET['asin'])){
            if($title == 'Product Details Page' || $title == 'Compare Products Page'){
                $title = zen_get_titles();

            }

        }

    }

    return $title;
}

add_filter('the_title', 'zen_title_filter');

As you can see this filter updates both the menu title for the product details page and compare products page. But the behavior that I'm expecting is that it should only update the title of the post itself but not the menu title which in this case is also the same as the post title. Any ideas?

enter image description here