Advertisement
Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

Create Named Templates in WordPress

WordPress recognizes three special areas of a theme: header, footer, and sidebar. The get_header, get_footer, and get_sidebar functions default to loading header.php, footer.php, and sidebar.php, respectively. Each of these functions also supports a name parameter that allows you to load an alternative version of the file. For example, running get_header('main') causes WordPress to load header-main.php.

You may wonder why you’d use the name parameter when you can just create a template file named whatever you like and load it directly. The following are reasons for using the get_header, get_footer, or get_sidebar functions with a name parameter:

  • You use a standard naming convention that users can easily recognize and understand.

  • You can load specialized template files easily and quickly.

  • You offer a fallback that loads the unnamed template file if the named one doesn’t exist. For example, if you use the tag get_header(‘main’); in your template, but for some reason the header-main.php template file does not exist, WordPress defaults to header.php, which saves the integrity of your website display until you can load the header-main.php file correctly.

In short, use the name parameter feature if you have multiple, specialized Header, Footer, or Sidebar template files.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win an iPad Mini. Enter to win now!