How it works

When you call wp_enqueue_script, you're taking advantage of one of several JavaScript-specific functions included with WordPress. Some of the others include wp_register_ script, wp_is_script, and wp_print_scripts. The wp_enqueue_script function accepts the following parameters handle, src, deps, ver, and in_footer. Let's talk about which ones are required, and which ones are optional. Earlier in our example we used the following function to call a simple JavaScript file wp_enqueue_script(...

How to do it

In this recipe, we will be updating text seen on the administration side of WordPress and the front-end side, by using the localization functions_() and _e(). Go through all customized files and look for any existing text strings that are already contained within < php > tags. Add two underscores (_), and surround any output text string with parentheses. As an example, we will use the localization function_( text) to flag the Edit link in the WordPress posts loop...

Index

content styles 110, 249 featured-posts-tabs div 204 header styles 110 menu styles 111, 113 sidebar styles 111 ad_counter variable 51 after_every variable 51 alt_post variable 60 cat_id variable 41 cat_name parameter 58 content string 73 deps parameter 195 handle parameter 195 in_footer parameter 195, 196 myquery1-> string 57 number_words variable 66 page variable 42 post object 64, 167 post variable 49, 64 preset_widgets variable 106 size parameter 167 src parameter 195 style variable 254,...

Aligning images properly within a post

One of the most important things for your theme to get right when it comes to displaying media is also one of the easiest. WordPress uses a certain set of markup to decorate images displayed in posts, and this markup includes instructions on how to align the images within a post. The class declarations shown below cover cases where images are inserted into a post by using the WordPress tools. This is very important to theme users, and forgetting to properly account for aligning images will give...

Styling every other post differently

Styling every other post differently is a powerful technique for creating interest in your theme and leading a visitor's eye down the page. The options for styling are endless, but some of the most popular and pervasive options include changing background images, colors, layout items, and more. Open the template file in which you wish to style posts differently as they are iterated over. In general, you'll insert this functionality into a template like index.php or category.php. Place your...

Creating multiple loops in a single template

In advanced themes, there are often situations where you would want to display multiple Loops consisting of posts with different criteria. When doing so, you should make sure not to alter the normal default Loop or else some template tags will not work appropriately. First, decide what kind of Loops you want to create. Perhaps you want to create two Loops, based on different categories. Perhaps one Loop should have featured posts while the other has the default posts based on the page URL. For...

Uploading your theme to the Word Pressorg theme repository

This recipe covers uploading your theme to WordPress.org, and promoting your theme on the codex and the WordPress.org forum. You will need to have tested, validated, and packaged your theme for distribution. Learn more about packaging your theme in the recipe Packaging your theme for distribution. Create a page on your site by logging in to your WordPress control panel and selecting Pages and then Add New on the control panel menu. Using the screenshot shown below, follow along with the next...

Adding a theme options page

As a theme developer, you have to make a lot of choices when you create a theme. What text should be displayed in certain locations Will that text always be appropriate How many posts should you display in a featured item carousel How many levels should the nested navigation menu have Part of being a good developer is knowing when to make these decisions for your theme's users, and when to give the users a choice. Many WordPress users are not comfortable with editing PHP files, so you need to...

Adding a skip navigation link for usability

In general, most blog themes have four main sections Header with site title and logo Navigation links and other navigation aids, such as search forms Main content the main focus of the page Site footer, containing extra site information If a sighted user navigates to a page, they'll often be able to immediately locate and start consuming the content. They can click on links, scroll though articles, and find the information that they want, quickly and easily. However, for non-sighted users, or...

Creating an archives page template

After learning how to create a simple page template in the recipe Creating a simple page template, you're probably brimming with ideas for custom page templates that you can provide for your theme. However, if you're going to take the time to create any page templates at all, you should make sure that you provide your users with a useful Archives template. The Archives template can contain many things, but its main purpose is to help your users navigate around your blog in a way that makes...

Introduction

Creating a basic WordPress theme is great. You learn about The Loop, find the appropriate template tags to display the information that you want, and then you write some HTML and CSS to tie it all together. However, there comes a time when you're ready to take your themes to the next level. That is what this chapter is all about. In this chapter, you'll learn how to provide your theme's users with options about what is displayed and how is displayed. You'll also learn about localizing your...

Centering your sites layout in the browser window

One of the most popular ways to classify designs on the web is to delineate them as either fixed-width or elastic. Designers who want maximum control over the layout of text, images, and other site elements generally created fixed-width designs. Current trends dictate that fixed-width designs belong in the center of the browser viewing window. In this recipe, you'll learn how to center your design and make certain that your content is going where you want it to. You should have started writing...

Packaging your theme for distribution

In this recipe, we will go over the steps necessary to package your theme for distribution. Even if you never share your theme with the public, following these steps can help you organize your theme better, and test for any potential compatibility issues with plugins or other code. First, you need to prepare any plug-ins or custom functions that you have created, so that any tags or callbacks that were inserted into template files will not break or corrupt the theme. To do this, the function...

Creating Navigation

Menu Php List Categories

Listing all of the pages that exist on a blog Listing all of the categories defined for a blog Listing all of the tags in use on a blog Highlighting the current page in the navigation Adding a search function to a theme Getting the category page link from a category name Displaying page links only if the destination page exists Creating a category drop-down menu Creating drop-downs using child pages One of the most important aspects of any website is navigation. Making sure that a visitor can...

1

Finding documentation on WordPress.org Downloading themes from the WordPress theme repository Downloading themes from third-party websites Installing and activating a theme Getting the absolute directory path of the active theme Creating a theme from scratch Creating a theme by using a theme framework Adding expected WordPress hooks Including PHP files from your theme If you're going to be creating or modifying a WordPress theme, it pays to start with the basics. That's what this chapter is...

Word Press 28 Themes Cookbook

Over 100 simple but incredibly effective recipes for creating powerful, custom WordPress themes community experience distilled PUBLISHING All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the...