Change The Separator in The Title Tag in WordPress

[ad_1]

Title HTML tag in WordPress or on a web page in general, defines the title of the document and is used on search engine result pages (SERPs) to display the preview snippets for that particular page. Title tags are very important for SEO as well as social sharing.

Why Title Tags are Important for SEO

Title tag is the main text that briefly describes the content on the page and helps search engines to rank an article into SERPs. That’s why title tags have been considered one of the most important on-page SEO elements.

The Separator in The Title Tag in WordPress

Optimizing title tags for your WordPress site must be your number 1 priority and best practices includes using right keyword in the beginning of page title for higher ranking in SERPs. Along with keywords, title tag separators are also important part of the page title.

Although it has never been confirmed any real significative advantage of using one over the other or any negative impact on SEO for using different separator in the title tag of the page but it does attract eyeballs of visitors.

So in this article we will be focusing on how to change the separator in the title tag in WordPress.

Change The Separator in The Title Tag

WordPress by default use pipes “|” as separator in the title tag but we can change it to something of our choice very easily. Official documentation on codex for wp_title() suggests the following way to change the title tag separators. Here the first parameter is separator for the page title and we can change it to dashes, commas or anything else of our choice.

<title><?php wp_title( '|', true, 'right' ); ?></title>

This is the easiest way to change the title tag separators but it does not always work since many plugins modify WordPress title function to generate the page titles.

So the best way to change the separator in the title tag is to use wp_title filter for modifying the output of the WordPress title function. You can page this following code snippet in your WordPress theme’s functions.php file.

// change the title tag separators in WordPress
function wpcs_change_wp_title_separator( $title, $sep ) {
    // Set new separator
    $sep = '-';

    // Set new title with separator
    $title = str_replace( '|', $sep, $title );

    return $title;
}
add_filter( 'wp_title', 'wpcs_change_wp_title_separator', 10, 2 );

Upon adding the above code snippet, it will change the default page title separator “|” (pipes) with “-” (dashes).

[ad_2]

Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads