Best way to include a css file <link> element for a specific page

If I have a css or js file that I need on 1 page in a project I sometimes use the code below. Just checking if there is a better more reliable way I should switch to.

So, for example, I’d write this in the <head> section:


if(strpos($_SERVER['REQUEST_URI'],'all_boards.php') !== false){
	echo '<link rel="stylesheet" href="/css/pin.css">';
}

Well, there are multiple ways of doing this but it really depends on what your needs are. I would probably use your solution for a custom Website made with “vanilla PHP” (aka no frameworks) with a small number of php pages and features (like a small website with 10-15 php pages and a contact form for example).

For a big Websites with hundreds of pages and a lot of features, I would probably use a framework or a CMS.

Then, if I needed to specify a different CSS for a lot of pages, I would probably have an admin to manage this stuff (specific JS, CSS, content, etc.).

If you have only one “template” that you use for all your pages, it’s probably not that bad to manage 1 or 2 CSS files that way. But if you start to get a lot of different HTML templates and you need to manage those kind of specific stuff for a lot of pages, it could get messy :wink: