Follow Me on Twitter!

You are reading Make your Own WordPress Theme – Part 2. To read other parts, click on the link below.

Part 2 will be more detail on things and functions needed to put in your WordPress header file. Open your header.php file.

  1.  
  2. <html>
  3. <head>
  4. <title>My WordPress Theme</title>
  5. </head>                
  6. <body>
  7. <div id="wrapper">
  8. <div id="header">
  9. </div> <!– close header –>
  10. <div id="content">
  11.  

Now, we are going to put wordpress functions into our header. We start with the title first.

Because WordPress is dynamic, so we can make our site has dynamic title by put this <?php wp_title(); ?> between <title> and </title>. This tag is use to call the title of the page.

  1.  
  2. <title><?php wp_title(); ?></title>
  3.  

But to make the title more interesting, we use the title tag with other PHP codes.

Just copy and paste this code between <title> and </title>.

  1.  
  2. <?php wp_title(); if (function_exists(‘is_tag’) and is_tag()) { ?>Tag Archive for <?php echo $tag; } if (is_archive()) { ?> archive<?php } elseif (is_search()) { ?> Search for <?php echo $s; } if ( !(is_404()) and (is_search()) or (is_single()) or (is_page()) or (function_exists(‘is_tag’) and is_tag()) or (is_archive()) ) { ?> at <?php } ?> <?php bloginfo(‘name’); ?><?php bloginfo(‘description’); ?>
  3.  

And it will look like this

  1.  
  2. <title>
  3. <?php wp_title(); if (function_exists(‘is_tag’) and is_tag()) { ?>Tag Archive for <?php echo $tag; } if (is_archive()) { ?> archive<?php } elseif (is_search()) { ?> Search for <?php echo $s; } if ( !(is_404()) and (is_search()) or (is_single()) or (is_page()) or (function_exists(‘is_tag’) and is_tag()) or (is_archive()) ) { ?> at <?php } ?> <?php bloginfo(‘name’); ?><?php bloginfo(‘description’); ?>
  4. </title>
  5.  

The next thing that we will do is to import our stylesheet file to be use in our theme.

  1.  
  2. <?php bloginfo(‘stylesheet_url’); ?>
  3.  

This tag will return our stylesheet url. Put this tag after </title>. But make sure that your CSS file named with style.css.

  1.  
  2. <style type="text/css" media="screen">
  3. <!– @import url( <?php bloginfo(‘stylesheet_url’); ?> ); –>
  4. </style>
  5.  

There are some other tags that we need to put in. Just copy this code below and paste it before </head>

  1.  
  2. <link rel="stylesheet" href="<?php bloginfo(‘stylesheet_url’); ?>" type="text/css" media="screen" />
  3. <link rel="alternate" type="application/rss+xml" title="<?php bloginfo(‘name’); ?> RSS Feed" href="<?php bloginfo(‘rss2_url’); ?>" />
  4. <link rel="pingback" href="<?php bloginfo(‘pingback_url’); ?>" />
  5. <meta name="generator" content="WordPress <?php bloginfo(‘version’); ?>" />
  6.  

Last thing that we need is to put <?php wp_head(); ?> in header.php.

Finally, your header.php file will look like this.

  1.  
  2. <html>
  3. <head>
  4. <title>
  5. <?php wp_title(); if (function_exists(‘is_tag’) and is_tag()) { ?>Tag Archive for <?php echo $tag; } if (is_archive()) { ?> archive<?php } elseif (is_search()) { ?> Search for <?php echo $s; } if ( !(is_404()) and (is_search()) or (is_single()) or (is_page()) or (function_exists(‘is_tag’) and is_tag()) or (is_archive()) ) { ?> at <?php } ?> <?php bloginfo(‘name’); ?><?php bloginfo(‘description’); ?>
  6. </title>
  7.  
  8. <style type="text/css" media="screen">
  9. <!– @import url( <?php bloginfo(‘stylesheet_url’); ?> ); –>
  10. </style>
  11.  
  12. <link rel="stylesheet" href="<?php bloginfo(‘stylesheet_url’); ?>" type="text/css" media="screen" />
  13. <link rel="alternate" type="application/rss+xml" title="<?php bloginfo(‘name’); ?> RSS Feed" href="<?php bloginfo(‘rss2_url’); ?>" />
  14. <link rel="pingback" href="<?php bloginfo(‘pingback_url’); ?>" />
  15. <meta name="generator" content="WordPress <?php bloginfo(‘version’); ?>" />
  16.  
  17. <?php wp_head(); ?>
  18.  
  19. </head>
  20. <body>
  21. <div id="wrapper">
  22. <div id="header">
  23. </div> <!– close header –>
  24. <div id="content">
  25.  

Next, Part 3 – Index . [tags]diy, how to, skin, theme[/tags]

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to StumbleUpon

Subscribe me feed! If you enjoyed this article, get latest updates via RSS feed or by email.

24 Responses to “Make your Own WordPress Theme – Part 2”

  1. azraai
    December 14th, 2006 | 12:40 am | Reply

    dari ko wat tutorial mcm ni. baik ko terang satu-satu tag template WP. bukan semua org faham kal wat tutorial mcm ni.

  2. Undertypo
    December 14th, 2006 | 8:40 am | Reply

    Yeah, I think you better explain more about all the tag that you use in header.php.

    If there is A newbie that trying to create a wordpress theme, do you expect he just copy and paste all the code? At least he/she need some explanation regarding all the coding.

  3. novatech
    December 14th, 2006 | 12:53 pm | Reply

    i think this is already good, the structure of theme.
    go read youself at wp codex for more explaination for the function used
    “good programmer learn from examples”, and always use multiple sources
    good luck :)>-

  4. dinswok
    December 14th, 2006 | 4:56 pm | Reply

    yeah… this is just the rough explanation. Any details regarding the meaning of each code can be found somewhere else. But… hmmm.. i wish i could read all those details here. Haha!

  5. CypherHackz
    December 14th, 2006 | 6:39 pm | Reply

    [Comment ID #15604 Will Be Quoted Here]

    okies. aku dah start kat part 3. sudi2 la men’review nyer. :d

    [Comment ID #15610 Will Be Quoted Here]

    same2. check out my 3rd part. :)

  6. goggle
    February 6th, 2007 | 2:03 pm | Reply

    A better explanation of the tags would be really useful :)

  7. CypherHackz
    February 6th, 2007 | 5:35 pm | Reply

    for the tags, you can learn them here:

    http://codex.wordpress.org/Template_Tags/

  8. mr.eims
    April 1st, 2008 | 3:19 pm | Reply

    hurm..bagus..bagus..ko nie rajin btol..hehe
    mesti ko dah expert ngn sume tags2 dlm WP nie..hehe..

    buat la theme utk latest WP plak..:)

  9. rohaza
    June 24th, 2008 | 3:03 pm | Reply

    yang ni dah cukup bagus…

  10. Anne
    June 27th, 2008 | 2:25 am | Reply

    oh my poor brains..though that article is really helpful but PHP code from “Part 2 – Header” is really awesome.Anyway, Thank you!!!

  11. Senpai
    November 24th, 2008 | 11:16 pm | Reply

    i cant proceed part 2…hard la

  12. Dana
    December 2nd, 2008 | 1:40 am | Reply

    Thank you for this tutorial, though it may behoove you to actually listen to your audience. You have multiple requests here for better explanation of the information presented. Though the lesson may be straight forward for you, I’m assuming you wrote this tut for your readers to read…not simply for yourself.

    I was surprised that you simply said “copy and paste this code”. That doesn’t necessarily constitute a tutorial and judging by your readers’ comments, they’re letting you know that, as well. Taking into account feedback from your audience will only strengthen you…you may want to listen.

  13. Tor-Arne
    December 28th, 2008 | 8:13 am | Reply

    Hi! I am having trouble making the CSS work, what might be the problem? It just wont work. Everythings shows up and all, but just under each other.

  14. Arif
    January 11th, 2009 | 10:14 am | Reply

    Good share about make a themes wordpress

  15. Kimbah
    April 29th, 2009 | 1:31 pm | Reply

    Thank you for sharing such a good tutorial :)

  16. Umar
    September 9th, 2009 | 11:59 pm | Reply

    Hi,

    I made everything the tut said….in the i got this..

    Fatal error: Call to undefined function get_header() in D:\wamp\www\wp\index.php on line 1

    now i made the header file with name: “header.php”,
    so what is that I am doin wroing…

    I would send you the file but i cant find any place to attach it & send it to you.

    Thank you.

  17. peter
    November 8th, 2009 | 4:15 am | Reply

    tutorial – teaching others something in layman’s terms. Once you start throwing all the extra code in without saying what the hell it is or does you lose people. I’d like to understand what I’m coding before I throw things out there!

  18. Stefan
    April 9th, 2010 | 10:38 am | Reply

    Thx sooo much! I forgot the in my header.php and was wondering why the lightbox 2 plugin did not work properly. Now i fixed it and lb 2 works fine. You made my day!

  19. Christian Voigt
    April 25th, 2010 | 9:24 am | Reply

    I really don’t get what some of you are complaining about. This tutorial is extremely helpful.

    And you can copy and paste the lot and have a working template too, don’t even need to be brainy for that.

    But nobody can teach you to understand things, for this you have to work, work and work some more.

    You don’t get what the more interesting title code does? Dont’t use it, the simple version is there too. Use that.

    You want to learn how it’s done properly? Take apart the more complex code and try to understand what is being done there. If you can’t, then you have some more work to do, like learning php and how to read and work with manuals and api’s. There is nothing here but simple php logic and well documented WordPress Template-Tags

    You really can’t expect this to be part of any tutorial. That would be enough material for several books. Books which have already been written at that.

    Thanks for this tutorial, it helped me get in tune with wordpress-template-programming. I will now wolf through the api-docs :)

  20. amran
    May 1st, 2010 | 10:52 am | Reply

    This is too much helpful . Thanks for this tutorial..

  21. Matt
    June 3rd, 2010 | 4:56 am | Reply

    I’m completely new to this. I have extremely basic html programming experience from about 10 years ago and I found this helpful. I realize that I need to learn to do some things to really understand what’s going on here. After looking at some of the tags here, there is simply no way the author can explain the code in any detail and not have this part of the tutorial end up waaaaaaaay too long. That’s my take. Happy code hunting. Make it fun and learn what you can.

Leave a Reply