Is it good practice to add php include to the chapter section of my pages?

I am creating my website for a portfolio and I want to include the title as php include on my page. The reason is that there will be quite a few pages on the site, and I want to subsequently make changes to some things, for example, when collecting css files.

For instance:

<head> <?php include('head.php'); ?> </head> 

unlike all this, below is shown on each page:

  <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title></title> <meta name="description" content=""> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="css/normalize.css"> <link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="css/1140.css"> <link rel="stylesheet" href="css/ie.css"> <script src="js/vendor/modernizr-2.6.1.min.js"></script> </head> 

I just did not know if this was really good practice, since this is my portfolio site, I need the code to be correct from the very beginning, as they will probably also learn its standard.

What are your opinions and advice to people? Thanks.

+4
source share
5 answers

Yes, this is quite standard. But instead of writing:

 <head> <?php include('head.php'); ?> </head> 

you must put the tags inside head.php . I say this better because inside head.php there is no point without headings, so they are related to each other. It is good practice to combine things related into one file without having to repeat the open and closed head tags for each page.

In fact, even good practice (and is usually used) has header.php , body.php and footer.php , which have respectively:

header.php

 <html> <head> ... </head> <body> 

body.php

 ... 

footer.php

 </body> </html> 
+13
source

I do this in my application, but I found that this is not a good idea, because you have a lot of your stylesheets, javascripts, etc. in the php file, including the chapter section, and you will have problems with including this in php files in subfolders. this problem is related to relative paths. If you can use absolute paths then this is normal, otherwise it is not a good idea ...

+6
source

PHP Includes has been used all this time. Anytime you have content that is the same on every page, it’s very useful to use include

+4
source

This is an old topic, but I use

  <?php include_once("phpinclude/head.txt"); ?> 

phpinclude is its own folder, and I save the information about the footer, the header and the general place in this folder..js and .css also has its own.

+1
source

Will it be bad in terms of SEO? on it, and if you turn on your head like this, all pages have the same title.

0
source

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


All Articles