An SEO Friendly PHP Include Alternative

For years now I’ve been using a technique that most programmers rely on for bringing content to their website. The PHP include functions. You simply add:

<?php
include(‘filename.php’);
?>

To your site, when you need to introduce a new element that would be present in several locations. For years this technique served me well, and made it quick to add in headers. All of the information was the same across the board, and for much larger sites, made little updates easier. I remember one of my first jobs in the industry required a link needing to be removed from the main menu. I ended up going into the site and changing over 50 pages and thinking to myself “There must be an easier way”. Shortly thereafter, I learned the power of the PHP include. Fast forward a few years later, and I get a call from one of my clients. The PHP include was great, but the SEO team he’d taken his website to had an issue with the way my site had been built. They wanted each page to have custom keywords, descriptions, and titles to each individual page. My client informed me he’d still pay me for my services, and that he’d still work with me in the future but I’d need to find a solution for this issue.

I looked at the code and thought to myself once again “There must be an easier way to do this”. It was at this point did I decide to try something new. A PHP class that would house all the information I needed. It would not just have the header information, but carry my template files such as the footer information, and navigation information too.

So I went to task and created a SiteManager.php class that would allow me to pass the variables I required in order to get the meta data set up. Once I got to work on it, it was pretty easy to do.

<?php
require_once(‘functions/SiteManager.php’);
$site = new SiteManager();
?>

The first thing I did was call the function I’d be creating into the file I needed. By using the require_once function, I insure that my class is loaded into the document. I also decided set up $site as the variable to manage all of the functions in my class.

<?php
require_once(‘functions/SiteManager.php’);
$site = new SiteManager();

// This defines the variables that will be needed for the header function.
$keywords = “Andrew Kelly, Andrew, Kelly, Pristine Pixels, Web Design, Web Development, PHP Programming”;
$description = “This is a website for Andrew Kelly, a web designer and developer just outside of the GTA”;
$title = “Andrew Kelly – Web Design and Development”;
?>

Next I defined the variables I needed in order to pass to my PHP function. These variables would be placed on every page and would have the ability to be changed depending on the page content to best reflect what the page is talking about.

<?php
require_once(‘functions/SiteManager.php’);
$site = new SiteManager();

// This defines the variables that will be needed for the header function.
$keywords = “Andrew Kelly, Andrew, Kelly, Pristine Pixels, Web Design, Web Development, PHP Programming”;
$description = “This is a website for Andrew Kelly, a web designer and developer just outside of the GTA”;
$title = “Andrew Kelly - Web Design and Development”;

// Call the header function, and pass the variables required.
echo $site->header($keywords, $description, $title);
?>

I then call my header function, and pass the variables I’ve set up. Once I’ve done this, everything I need to do for the page with the content is done. All of the information has been set up. Next I would create the PHP class that would handle all of the data.

<?php
class SiteManager {

function __construct() {
// Here you would set anything might be needed in all the functions. In this case, nothing is required to go here.
}

}
?>

The next step is to create the class. First I set the __construct() function to activate the function. You don’t need to set anything up inside this function, but the function itself is always required.

<?php
class SiteManager {

function __construct() {
// Here you would set anything might be needed in all the functions. In this case, nothing is required to go here.
}

function header($keywords, $description, $title) {

$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"';
$html .= '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';

$html .= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
$html .= '<head>';
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
$html .= '<meta name="description" content="empty />';
$html .= '<meta name="keywords" content="empty" /> ';
$html .= '<title>untitled</title>';

$html .= '</head>';
return $html;
}

}
?>

I proceeded to add my header content into one large variable called $html. This way way when I return the variable all of my information is showcased where I requested it to be. When you use an echo in a function, the text you’re using can jump around and may display above other content. By using a variable to house the information, you can ensure that everything loads correctly when requested.

<?php
class SiteManager {

function __construct() {
// Here you would set anything might be needed in all the functions. In this case, nothing is required to go here.
}

function header($keywords, $description, $title) {

$html = ‘<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”’;
$html .= ‘“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>’;

$html .= ‘<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>’;
$html .= ‘<head>’;
$html .= ‘<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8”/>’;
$html .= ‘<meta name=”description” content= “’.$description.’”/>’;
$html .= ‘<meta name=”keywords” content=”’.$keywords.’” /> ‘;
$html .= ‘<title>’.$title.’</title>’;

$html .= ‘</head>’;
return $html;
}

}
?>

Finally I break drop the variables in by inserting them into the php where required and everything needed is done.

By using this technique, you can still have all of the information stored in one location, but the php functions allow you to pass the variables required to make everything dynamic. The code is clean, still easy to read, and makes a lot of people happier.

Since I started using this approach I haven’t had any more issues with any SEO teams **knock on wood** and my clients are just as happy as ever. Hopefully this helps someone else out there struggling with PHP includes and SEO issues.



Posted in Uncategorized | Leave a comment

Burnouts

Two years ago I experienced what it’s like to burn out in the industry. It’s funny because I had heard about this sort of thing from co-workers but I never experienced it myself and the blogs I loved to read so much never seemed to touch on it. I was convinced that burning out only happened when someone didn’t care about the industry enough to “suck it up and just pull through”.
I learned how untrue that statement was after working every single night, pulling constant 48 hours weekends, and having my phone ring off the hook constantly. I remember that I had once moved a couch with a buddy up two flights of stairs and the entire time my phone was ringing as my current work had some important updates that needed to be made at 9:00 pm on a Wednesday night.
I had burnt out because while I loved the industry I was in, I had also been placed in a position where I had been taken advantage of. I was so eager to please my employers that I didn’t take the time to realize how unhealthy it was for me both in the short term and long term.
What surprised me about burning out the most, was the lasting effects. I left that job and proceeded to work for another company that didn’t exactly require me to strain myself in terms of expectations. It was a dull, cubicle-built, large corporation where I was considered “just a number”. It was great because I wasn’t expected to stay late every night and it didn’t feel like the weight of the entire company rested on my shoulders.
However, as great as it was to have limited expectations in my role, it didn’t exactly rekindle that love of the industry I once had. I used to learn new languages, have photoshop open non-stop, blog anything that came to mind, and just be involved in the web field overall. Now all I cared about was going to work, getting my pay check, and coming home. There was no drive, and no love. It was just a job, and looking back I realize how terrible that was.
My burnout had been so severe I lost all interest in the industry. It wasn’t until I had been laid off due to the automotive crisis, did the first glimmer of hope shine through. I looked up to the freelancers of the web industry. I looked up to guys like Jonathan Snook, Ryan Carson, Jason Santa Maria, Bryan Veloso, and so many others. I wanted to succeed like they had, and become a top reference in the web industry. When I first started out, I  started to find that same love I once had for this industry.
Unfortunately I failed, because I wasn’t ready to be in that freelance position. What you don’t read from people is just how difficult it is to be a freelancer. You don’t read about the clients who can’t pay you in time and how that results in massive credit card debit. You don’t read about how nearly every “lucky break” seems to have a catch that will set you back either financially or just in over success.
So after struggling for close to a year, I decided I’d go back into a full time position completely jaded by industry. The last dream I had, I didn’t succeed at. Since college I dreamed of being a successful freelancer and my attempt at it didn’t pan out. I was so bitter and even considered leaving this career path all together.
I started my new job, and decided that I would finish my up my freelance obligations and just take a break from the freelancing side of the industry. I would focus on my full time position as a Web Developer at Whatever Solutions & Media and once I left the office at 5:00 pm; I wouldn’t look at my computer or any job requests that would come in.
I proceeded to get married, and for about five months I just took it easy. I didn’t stress out about anything, didn’t worry about the latest web trends, and just enjoyed being a newly wed.
I find it funny that because of the break, my desire to get involved in the web industry outside of my job has increased. It started with twitter, as I’d just read the occasional article on design trends, development tips, or web site showcases. Now I’m back in a place where I’m playing around in Photoshop constantly, Illustrator has had the dust blown off as I try new ideas, and I’m writing for the first time in years.
I don’t know what others try, but I thought to get over a burnout the key was to just work through it. As it turns out out, the best way to get past it, is to just walk away for a little bit. The best thing I ever did was take some time for me and sure enough the passion for the industry I once had started coming back to me once I had a long enough break.

Posted in Uncategorized | Leave a comment