PHP - use H1 tags as page title

I just started with php. I have a pretty simple site with a header and footer, as well as content between them.

Now I have every page that gets the title with a variable, for example:

<?php $title = "My Company - New Products"; ?>

However, instead of having this on every page, in the include heading, I just want the heading to be the standard “My company” and then pick up each H1 tag of each page.

It seems simple, but all my search results were specific to different CMS.

Many thanks.

+3
source share
3 answers

Why not identify $titleand then refer to it more than once in the header?

Main page:

<?php
$title = "New Products";
require "header.php";
?>
<p>Rest of page...

header.php:

<title>My Company - <?php echo htmlentities($title) ?></title>
<h1><?php echo htmlentities($title) ?></h1>
+4
source

-, PHP H1 HTML, , HTML- ( ...)

, PHP. , HTML. , Smarty, , PHP .

PHP - jleedev. PHP ( ) - HTML ( ). , HTML - .

+1

I agree with jleedev, but I use require () instead of include.

And don't use shorthand php tag ( <?)!

0
source

Source: https://habr.com/ru/post/1772727/


All Articles