Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress set custom title on custom page

Tags:

php

wordpress

I am trying to create entirely custom page but using the same functions for creating header and footers in WP. I have this on my page

<?php
include("../wp-blog-header.php");
get_header();
?>
<title>My Custom Title Here</title>
<?php
wp_head();
get_footer();
?>

The page is displaying all fine, but when I am trying to add <title>My Custom Title Here</title> after get_header() I am getting this in my page source as title Page not found &#8211; My Custom Title

How can I set custom page title? I mean after the page loads the title should be <title>My Custom Title Here</title>

like image 475
Yunus Aslam Avatar asked Oct 29 '22 12:10

Yunus Aslam


1 Answers

Maybe not ideal, but I've done the following in a pinch. With some additional logic you could add it to your functions.php, but if you really just need it for a single page I'd just include the filter in that specific file, before calling get_header().

<?php
include("../wp-blog-header.php");

add_filter( 'wp_title', 'custom_title', 1000 );
function custom_title($title) {
    $title = 'My Custom Title Here';
    return $title;
}
get_header();
?>
<?php wp_head(); get_footer(); ?>
like image 58
emsoff Avatar answered Nov 15 '22 07:11

emsoff