Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

74 PART II • Designing and Developing WordPress Themes


<?php
// The title
wp_title( '|', true, 'right' );
// Add the blog name.
bloginfo( 'name' );
?>
</title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="<?php
bloginfo( 'stylesheet_url' ); ?>" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<!-- Fix for Internet Explorer prior to version 9
by Remy Sharp http://remysharp.com/2009/01/07/html5-enabling-script/ -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<?php
// Always have wp_head() before closing of head
wp_head();
?>
</head>

You’re using conditional tags to check whether the user is on an archive, a single post, or a
page and to act accordingly after that. Also worth noting is that I’ve chosen to keep the
Internet Explorer HTML5 fix separate within HTML conditional, rather than load said
JavaScript with wp_enqueue_script(), which normally would be the right thing to do.
I’m keeping it separate to make sure that the HTML browser check works as intended and
because I really don’t want any browser besides Internet Explorer versions prior to 9 to load
this JavaScript. Finally, there’s the queuing of the JavaScript for comment replies, loaded only
on single posts and pages as that’s the only way it can be used — and last but not least, the
ever-important wp_head(). You always want wp_head() just above your closing head tag,
as this is where a lot of plugins and theme-enabled features will insert code that is supposed to
be run in head, and you want to do that after you’ve gotten everything else out of the way.

Moving on, you need to take care of the rest of header.php. Here you want to make sure that
the body tag gets the proper classes (good for styling with CSS, obviously), make sure that the
correct site title and site description is outputted, and make sure that the menu doesn’t have to
be hardcoded but can be used using WordPress’s menu feature:

<body <?php body_class(); ?>>

<div id="outer-wrap">
<div id="inner-wrap">
<header id="header-container">
<hgroup>
<?php if ( is_home() || is_front_page() ) { ?>
<h1 id="site-title">
<a href="<?php echo home_url(); ?>" title="<?php
Free download pdf