Ian
Ian

Reputation: 865

Setting a Custom SEO Title Using Yoast Wordpress SEO API

I've just installed this plugin on my site and it means that my custom titles that were previously set no longer work. Here's the link to the brief Wordpress SEO API doc: [http://yoast.com/wordpress/seo/api-docs/]

Previously, I did this:

$pagetitle = '' . $design['name'] . ' | Free Design from My Site';

I have a custom URL rewrite that takes a WP page /design/ and appends the design name to /design/design-name so now I've installed WP SEO, the page title is whatever the title of /design/ is and isn't specific.

According to the docs in the link above, I tried this:

function wpseo_design_detail_title($pagetitle) {
$pagetitle = $design['name'] . ' | Free Web Template from My Site';
}
add_filter( 'wpseo_title', 'wpseo_design_detail_title' );

That does remove the previous /design/ title but instead it just has the sites URL (i.e. the page title is blank).

I'm probably missing something really simple, right?

Upvotes: 1

Views: 4828

Answers (2)

its_me
its_me

Reputation: 11338

This is how it's done:

function YourFunctionName( $title ) {
 
    $title = 'Your Webpage Title';

    return $title;

}
add_filter( 'wpseo_title', 'YourFunctionName' );

But @user1502679 suggested, you can use the WordPress' wp_title filter (but it only works if WordPress SEO by Yoast is disabled):

function YourFunctionName( $title, $sep ) {

    $title = 'Your Webpage Title';

    return $title;

}
add_filter( 'wp_title', 'YourFunctionName' );

Upvotes: 3

user1502679
user1502679

Reputation: 566

why you use Yoast? just add a filter to wp_title

Upvotes: -2

Related Questions