Grow your CSS skills. Land your dream job.

PHP Possibilities

  • # November 18, 2012 at 1:56 pm

    Ok so i have a head.php file that i am including to some of my pages that have the same heads. However i am at a loss on how to get page specific things like the title tag, facebook’s open graph, and other things required for SEO, inside the head without writing it all out. Is there a variable for that?

    Cheers

    # November 18, 2012 at 2:18 pm

    There’s a few ways you can do this, either by breaking up your head.php into, for example, doctype.php (where you put, doctype and meta charset etc). Then call that on your page.
    Then have your title tags on each page.

    Then have head.php full of the stuff after that.

    Alternatively, what I do is pass a variable, usually to the body class, but it will work in the case of title tags too.

    For example, when you call your file at the top of each file/page, create a line above with a variable.

    For example:

    < ?php $pageTitle = "Page Title Goes Here";?>

    Then in your head.php have;

    It will grab the variable from the document and then echo it out inside your title.

    I also do this for body classes (if needed) where I do;

    < ?php if (empty($bodyclass)) {echo 'DEFAULT_CLASS_GOES_HERE';} elseif (!empty($bodyclass)) {echo $bodyclass;}?>

    The above basically sets the default body class if there isn’t one passed through, but if there is, it echo’s it out.

    __
    # November 18, 2012 at 2:19 pm

    > Is there a variable for that?

    There’s a variable for anything,

    as long as you assign a variable to it : )

    for example

    < ?php
    $title = “My Page Title”;

    $template = < << HTML
    < !doctype html>


    HTML
    ;

    print $template;

    # November 18, 2012 at 8:52 pm

    @andy_unleash @traq Thanks guys!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".