Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a wordpress page that will output product details of a specific product from amazon: wordpress/product?asin=123

I'm just using the product page as a template and it really contains nothing. I'm just adding a filter to the content to put some contents into it.

I'm also using the wordpress seo plugin from yoast to take care of SEO stuff but it seems to be getting in the way. I currently have this code:

function ecom_title_filter($title){

    if(is_singular()){
        if(!empty($_GET['asin'])){
            if($title == 'Product Details Page'){
                $asin = $_GET['asin'];
                $titles = get_titles($asin);
                if(count($titles) == 1){
                    $title = $titles[0];
                }else{
                    $index = 1;
                    $title = '';
                    $title_count = count($titles);
                    foreach($titles as $item_title){

                        if($title_count > $index){
                            $title .= $item_title . ', ';
                        }else{
                            $title .= $item_title;
                        }

                        $index++;
                    }
                }

            }

        }

    }

    return $title;
}

Then I'm adding it into the the_title and wp_title:

add_filter('the_title', 'ecom_title_filter');
add_filter('wp_title', 'ecom_title_filter');

The problem is that the page still retains the old page title which is Product Details Page and not the title that I'm returning from the method above. The method returns what I expect it to return so the problem is not the method. Any ideas?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Either deactivate the filter from the SEO plugin for that page with remove_filter() or use a later priority argument like this:

add_filter( 'the_title', 'ecom_title_filter', PHP_INT_MAX );
add_filter( 'wp_title',  'ecom_title_filter', PHP_INT_MAX );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.