Change the Page Title Dynamically

by Sam  

Page title is one of the considerations by the search engines to crawl with. Therefore, it is important to have a user-friendly page title.

In wordpress, you have different ways to set the page title.

Option 1

add_filter('wp_title', set_page_title());
function set_page_title() {
$title = 'Page Title - '.get_bloginfo('name');
return $title;

Note that the above code works only on codes below wordpress 4.4 version. Check the link below.

Document title in 4.4

Option 2

This solution only works on Main Page title but not changing the bloginfo name.

function custom_title($title_parts) {
$title_parts['title'] = "Page Title";
return $title_parts;
add_filter( 'document_title_parts', 'custom_title' );

You might also like to test the code below:

function custom_title($title) {
return "Page Title";
add_filter( 'pre_get_document_title', 'custom_title' );

If you have another way of changing the page title, don’t hesitate to comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Need of a Website?

Maybe you're planning to build a landing page for your website. You might also have a plan to create a web application. I can offer you with an affordable but with good quality services. Don't hesitate to submit your specifications by clicking the button below.

Get Quote