Force rewriting of the title of a page

2

Well I have a page, but one of these pages wanted me to change the title. Example my page uses in Reader a code that defines the title of all pages, but I have a page in custom php that also want to put a different title, ie Rewrite the title that is already defined in Reader, there is some form in PHP or any other to do that?

<?php   
include_once "./includes/header.php";   
 <!-- AQUI VAI MEU CONTEÚDO -->  
include_once "./includes/footer.php"; 
?>

It would be like this, but I can not edit the header.php You will then have to force the title to change by what is in%% of%

    
asked by anonymous 05.04.2018 / 20:54

1 answer

3

You can do this using JavaScript or jQuery, but it would be better if you chose to edit directly in ./includes/header.php .

In JavaScript:

document.title = 'Novo título';

jQuery:

$('title').text('Novo título');

Another solution, which I believe can also be done in a better way. It would be you in ./includes/header.php where you set the title to pass a variable instead of a static text like:

Using short tags :

<title><?= $page_title ?? "Título estático" ?></title>

Using traditional tags:

<title><?php echo $page_title ?? "Título estático"; ?></title>

In this example, if I am not mistaken, it checks whether the $page_title exists using the isset function, if it exists, its value is passed, otherwise, "Static title".

And so you would add the variable before ./includes/header.php in this way:

<?php
// Define o título aqui.
$page_title = 'Título da página';

include_once "./includes/header.php";   
<!-- AQUI VAI MEU CONTEÚDO -->  
include_once "./includes/footer.php"; 
?>
    
05.04.2018 / 21:14