This post includes WordPress functions that I find myself using over and over again when creating themes for WordPress. These functions are for the most part basic, but they are very useful and every WordPress developer should know them.
Used in header.php, wp_head() triggers the wp_head hook that is pretty much required in order to run a smooth WordPress website. Plugins rely heavily on this function to make references to script files, jQuery libraries, stylesheets, etc. It must be place within the opening and closing head tags.
Similar to wp_head(), wp_footer() is also used to call files required by many plugins. It must be placed right before the closing body tag.
Used to display information about your site, such as site name, description, url, stylesheet url, template url, and more. Example:
4. get_header(), get_footer(), get_sidebar()
Functions used to include the template files header.php, footer.php, and sidebar.php respectively. They are the base of a WordPress template.
Note: You can also use name parameters to these functions in order to call for different template files. This is very handy when the layout of a website changes on different pages. For Example:
The example above would include template files named header-contact.php and footer-contact.php, allowing you to create custom headers and footers without altering your main header.php and footer.php files. It also works with get_sidebar().
This is one of my favorites WordPress functions. It’s used to display something on the home page of a static front page setup under Appearance > Reading. Example:
Very similar to is_front_page(), is_home is used to display stuff on the home page of a website with “latest posts” front page setup under Appearance > Reading. Example:
Checks if a specific page or set of pages are being displayed. You can use page id, name, or slugs as parameters, like so:
// Page Name
// Page ID
// Page Slug
// Pages with ID's 45, 60, 72
// Pages About Us, Contact Us and Testimonials
Targets the single post view. The page after you click to read a post. It also accepts post id, post title, and slug parameters.
Checks if a category archive page is being displayed. You can also target specific category pages by using parameters in the function. Those can be Category ID, title, slug or an array of ID’s, names and slugs. For example:
Checks if any type of archive page is being displayed
Used to display pages as links on your site. You can arguments to display all pages, child pages of a specific page, order the pages, and more. Example: