Different wp_title and WooCommerce page title by terms

In a project I needed wp_title with the separator, but WC page title without separator for specific terms of a taxonomy.

Here’s the code I used:

/**
 * Add more descriptive page title to some taxonomy term
 *
 * @param string $title    Page title.
 * @param string $sep      Title separator.
 * @return string
 **/
function pf_fix_title( $title, $sep = null ) {

    $term = get_queried_object();

    if ( is_front_page() && $sep !== null )
        return "Lacné letné a zimné pneumatiky $sep";
    if (is_404() && $sep !== null )
        return "Stránka neexistuje $sep";

    switch ( $term->taxonomy ) {

        case 'pa_radius':
            $title = "$term->name-palcové pneumatiky $sep";
            break;

        case 'pa_season':
            $tax = get_taxonomy( $term->taxonomy );
            $title = "$term->name pneumatiky $sep";
            if ( $sep !== null )
                $title .= " $tax->label $sep";
            break;

    }

    return $title;
}
add_filter( 'wp_title', 'pf_fix_title', 10, 2 );
add_filter( 'woocommerce_page_title', 'pf_fix_title' );
Advertisements

About Michal Zuber

Biker and rollerblader. Owner and developer at http://nevilleweb.sk/ Co-founded http://neville.sk/ Blog at https://michalzuber.wordpress.com/
This entry was posted in php, woocommerce, wordpress and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s