WordPress 3 Cookbook

By Ric Shreves , Jean-Baptiste Jung
    Advance your knowledge in tech with a Packt subscription

  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. The WordPress Cook's Tools

About this book

Using the WordPress Content Management System, you can create a beautiful, dynamic, and amazing website. WordPress is a flexible and powerful tool that's ideal for creating both blog and non-blog websites. Are you feeling limited with WordPress, or are you wondering how popular blogs do a certain kind of thing that you can't?

WordPress 3 Cookbook focuses on providing solutions to common WordPress problems so that you can translate your site to one of the best. The author's experience with WordPress enables him to share insights on using WordPress effectively, in a clear and friendly way, giving practical hands-on solutions to WordPress problems, questions, and common tasks – from themes to widgets and from SEO to security.

With this update to the WordPress 2.7 cookbook, you will learn many WordPress 3 secrets and techniques, with step-by-step, useful recipes dedicated to achieving a particular goal or solving a particular problem.

You will learn to install and customize themes, work with plugins, customize content display, enhance interactivity with the user and build communities. Then, the book also teaches you to earn revenue through online sales and advertisements. You will also find recipes for SEO and enhancing usability, and the book finally winds up with information on the inevitable maintenance and security.

This book helps you to get solutions to common WordPress problems, to make your site better, smarter, faster, and more secure.

Publication date:
December 2011
Publisher
Packt
Pages
328
ISBN
9781849514606

 

Chapter 1. The WordPress Cook's Tools

In this chapter you will learn about:

  • Managing media files with the Media Library

  • Modifying theme files with the built-in Theme Editor

  • Modifying plugin files with the built-in Plugin Editor

  • Managing users

  • Gaining control over user roles and permissions

  • Setting up editorial workflow

  • Importing and exporting content

  • Installing and using Jetpack

  • Enabling the toolbar for users and administrators

 

Introduction


This chapter serves as an introduction to the basic tools and features that are part of your WordPress administration system. All of the topics discussed in this chapter relate to fundamental functionality needed to use the WordPress CMS. Most of the chapter is focused on tools that are included in the default WordPress system.

Understanding the tools discussed in this chapter is essential to understand how to get the most out of your WordPress site. There's a lot you can do with WordPress, even without installing additional plugins and custom themes. In this chapter, we look at how the basic tools enable you to work with users, set permissions, and workflow, and how you can even modify plugins and themes – all from within the WordPress administration interface and without the need for specialized or external tools.

 

Managing media files with the Media Library


WordPress includes a tool designed to help you deal with the media files for your website. The tool, called appropriately the Media Library, allows you to view and manage all your media files (images, videos, and so on) in one place.

Once you've added files to your Media Library, they are available to you as you work with the posts and pages of your site. The key advantage of using the Library is that you can work with images in bulk, uploading or deleting multiple images at one time.

In this recipe, we cover the basics of working with this useful tool, including adding, editing, and deleting files.

Getting ready

Everything you need for this recipe is located inside the dashboard of your WordPress site.

How to do it...

  1. Log in to your WordPress Dashboard.

  2. Click on the Media menu.

  3. To view the files in the Library, click on the Library option and you'll see the existing files, if any. The following screenshot shows you a typical view:

  4. To add a new media file to your Media Library, click on Add New.

  5. On the screen that loads in your browser, click on the Select Filesbutton and the system will show you a pop-up that lets you to select the media files from your hard drive.

  6. Once you locate the file you want, select it, then click the Upload button and the system will add the file to the Media Library. As it uploads, you will see a status bar showing you the progress.

  7. Once the upload is complete you can view the file in the library and edit the details, if you so desire. The following screenshot shows you the Upload New Media screen, where you can edit the image info. Once you finish with your edits, click on Save all changes.

Tip

There are two uploaders available: the Flash uploader and the Browser uploader. The Flash uploader allows you to select multiple files at once, while the Browser uploader allows you to upload only one file at a time. While the Flash uploader can be faster and more convenient, on some systems you may experience some difficulties using it. If you have any issues with the Flash uploader, simply choose the Browser uploader; it's slower, but it's very reliable.

To delete files from the Media Library, carry out the following steps:

  1. When inside the Media Library, simply hover the mouse over an item and the Edit, Delete Permanently, and View buttons will be appear.

  2. Click on Delete Permanentlyand the system will prompt you for confirmation.

  3. If you wish to remove the file, click on OK in the pop-up and the system will delete the file.

For bulk media deletion, carry out the following steps:

  1. Go to the Media Library.

  2. Select the checkboxes immediately to the left of the files you wish to delete.

  3. Select the option Delete Permanently from the Bulk Actionsdrop-down list (located above the list of files)

  4. Click on the Apply button.

Note

Be careful – when using bulk deletion, there is no confirmation dialogue! Once you click the Apply button the system will immediately delete all the files you have selected.

Editing files in the Media Library is limited to modifying the meta information associated with the file; you cannot actually edit the media file itself. To edit existing file's information, carry out the following steps:

  1. Access the Media Library.

  2. Hover the mouse over the item you'd like to edit and click on the Edit link that appears.

  3. In the page that opens, you can define the file settings. The following screenshot shows the Edit Media page:

  4. Click on the Update Media button when you're done and the system will save your changes.

 

Modifying theme files with the built-in Theme Editor


As you are probably aware, the appearance of your WordPress site is dictated by the theme you use. Themes themselves are comprised of a number of files, typically a mix of PHP and CSS files. Editing the files in your theme can be handled in one of two ways: either with a third party editor, or with WordPress' built-in Theme Editor. In this recipe, we introduce the basics of working with the Theme Editor.

Getting ready

Everything you need to complete this recipe is located inside your WordPress dashboard.

How to do it...

  1. Log in to your WordPress Dashboard.

  2. Click on the Appearance menu.

  3. Click on the option Editor.

  4. By default, the system will load one of the files from the active theme, as seen in the following screenshot. If you wish to change the view to edit a different file, simply click on the name of the file in the right hand column.

  5. Make your changes.

  6. When you're done, click on the Update File button to save your modifications.

How it works...

The Theme Editor simply provides an editing interface for the files in the active theme. You can change to edit the files of a different theme by selecting the theme name from the combo box labeled Select theme to edit.

Tip

Be cautious! Remember that when you edit a theme file in WordPress Theme Editor, you are editing the real file on the server. Once you press the Update File button, the file is saved and the previous version is erased. This is an issue of particular importance where the theme you are editing is the active theme on a live site.

There's more...

Although the Theme Editor is very convenient, you have to be careful with it.

Note

Depending on your web hosting environment, you may experience problems using the Theme Editor. Accordingly, it is essential that you have a back up of your WordPress files before you begin working.

  • Best practice is to create a backup of your theme before editing. If you have made a modification and later would like to undo the modification, you need to have a backup of the previous version of the file.

  • Use the Theme Editor only if you're sure about what you're doing. If you're editing your current theme and make a programming error (for example, a PHP syntax error), it is possible that your site will stop functioning until you correct the error.

  • Sometimes, a programming mistake can even result in you losing access to the Theme Editor. While this is quite a rare case (it mostly happens when you make a code mistake in the functions.php file), the problem is serious. You will most likely need to have a backup of your theme (as well as an FTP connection to your server) to sort out this problem.

See also

  • Chapter 2, Installing and Customizing Themes, covers WordPress themes in more detail

 

Modifying plugin files with the built-in Plugin Editor


Plugins are a vital part of your WordPress site, adding much of the key functionality to your site. Just as we saw with the Theme Editor in the previous recipe, you can edit plugin files directly from within the WordPress dashboard, without the need of a third party editor. In this recipe, we introduce the basics of working with the Plugin Editor.

Getting ready

Everything you need to complete this recipe is located inside your WordPress dashboard.

How to do it...

  1. Log in to your WordPress Dashboard.

  2. Click on the Plugins menu.

  3. Click on the option Editor.

  4. By default, the system will display one of the files from the first available plugin, as seen in the next screenshot. If you wish to change the view to edit a different file for the plugin, simply click the name of the file in the right hand column. To change to a different plugin, select one from the combo box labeled Select plugin to edit.

  5. Make your changes.

  6. When you're done, click on the Update File button to save your modifications.

How it works...

The built-in Plugin Editor works in exactly the same way as the Theme Editor. When a file is modified and saved, the modifications are written directly in the source file—there's no copy or backup.

Tip

The system provides a link to documentation for the plugin. If you look below the editing window in the previous screenshot, you can see a combo box labeled Documentation. Select the appropriate file from the list then click Lookup to view the documentation.

There's more...

The Plugin Editor is a very useful tool; however, it can also create problems if used improperly.

  • Unless you're very sure about what you're doing, always deactivate the plugin before editing

  • Always have a backup of the plugin you're editing, as the Plugin Editor does not save any revisions

  • If—after editing a plugin—your site does not function correctly, deactivate the plugin, and upload your plugin files backup to your wp-content/plugins/yourplugin directory

See also

  • Chapter 3, Working with Plugins and Widgets, covers WordPress plugins in more detail

 

Managing users


All WordPress sites include a combination of public and registered users. Registered users can be assigned to various roles that give access to different features of the site. WordPress includes a feature that enables you to manage the registered users of your website the Users Manager, as shown in the following screenshot:

In this recipe we introduce the Users Manager and the basics of creating, editing, and deleting registered users in WordPress.

Getting ready

Everything you need for this recipe can be found in the WordPress dashboard.

How to do it...

WordPress users manager allows you to add, edit, or delete user accounts. Let's learn how to do this in detail.

In order to add a new user, carry out the following steps:

  1. Log in to the WordPress Dashboard.

  2. Click on the menu labeled Users. The Users Manager, as shown in the previous screenshot, will load.

  3. Click on Add New.

  4. The Add New User screen in shown in the following screenshot. The only required fields are Username, E-mail, and Password (which must be entered twice). However, you should also check the Role control and make sure you are setting the right access privileges for the user.

  5. Once done, click on the Add New User button.

In order to edit an existing user account, carry out the following steps:

  1. Access the Users menu, as explained in the previous steps.

  2. Find the name of the user you wish to edit and hover the mouse over the name; the Edit and Delete buttons will be displayed.

  3. Click on the Edit button.

  4. On the next page, as shown in the next screenshot, you can edit the following information about the user:

    • Enable/Disable Visual Editor

    • Admin color scheme

    • Enable/Disable Keyboard Shortcuts

    • User Role

    • First Name, Last Name, and Nickname

    • How the user name should be publicly displayed

    • Contact info

    • User bio

    • Password

  5. Make the changes you desire.

  6. Click on the Update User button to save your modifications.

In order to delete a user's account, carry out the following steps:

  1. Access the Users Manager, as discussed previously.

  2. Find the user you'd like to delete (a mini search engine is included on the top right of the page) and place the mouse cursor over his or her name. The Edit and Delete button will appear.

  3. Click on the Delete button.

  4. The system will prompt you to choose between deleting the user and all the content which he has provided (posts, comments, and so on) or deleting the user, but transferring the content to another author. Make your selection.

  5. Click on Confirm Deletion.

Tip

You can also delete multiple users simultaneously by selecting them on the main users manager page, then choosing Delete from the Bulk Actions combo box.

See also

  • Gaining control over user roles and permissionssection in this chapter

  • Setting up editorial workflow section in this chapter

 

Gaining control over user roles and permissions


User permissions in WordPress are dictated by the role the user is assigned to. By default, the WordPress system includes five roles:

  • Admin

  • Editor

  • Author

  • Contributor

  • Subscriber

The permissions associated with each role are fixed and cannot be edited without the use of a plugin. While there are several plugins that provide this functionality, in this recipe we take you through using the User Role Editor and show you how to both modify existing roles and how to create new ones.

Note

To learn more about the default user roles and their capabilities, visit the WordPress Codex page on the subject at http://codex.wordpress.org/Roles_and_Capabilities

Getting ready

To execute this recipe, you will need to install the User Role Editor plugin. You will need to install this plugin before you can get started. Search for User Role Editor inside the Add New Plugins screen of your WordPress site. After you find it, click on it to install, and then activate it.

Note

You can learn more about the plugin by visiting the developer's website at http://www.shinephp.com/user-role-editor-wordpress-plugin/

How to do it...

To edit an existing role, follow these steps:

  1. Log in to your WordPress Dashboard.

  2. Click on the Users menu.

  3. Click on the options User Role Editor.

  4. On the page that loads, first select the role you wish to edit from the Select Role combo box.

  5. Make the changes you desire.

  6. Click on the Update button to save your changes.

Your changes will now impact all users assigned to the role you have edited.

Note

You cannot modify the Admin role.

To create a new role, follow these steps:

  1. Log in to your WordPress dashboard.

  2. Click on the Users menu.

  3. Click on the options User Role Editor.

  4. On the page that loads, enter a name for the new role in the Add New Rolefield.

  5. Click on the Add button.

  6. On the page that loads, select the privileges you want to role to enjoy.

  7. Click on the Update button to save your changes.

Tip

The fields marked level_x are only applicable to older, version 2 installations of WordPress and should not be used for WordPress 3. Note also that you can make the role capabilities easier to read by clicking on the check box labeled Show capabilities in human readable form, at the top right of the page.

How it works...

The plugin edits the default role settings and, by interfacing with the database, allows for creation of new roles. Those of you who wish to explore modifying roles without the use of a plugin will need to explore the WordPress Plugin API at http://codex.wordpress.org/Plugin_API

See also

  • Managing users section in this chapter

  • Setting up editorial workflow section in this chapter

 

Setting up editorial workflow


If you allow multiple people to post articles and pages to your site, you will want to stay up to date on what your authors and contributors are doing, and you may want to set up a system that allows posts to be reviewed and edited prior to publication. While you can always manage this manually by sending e-mails back and forth, that approach is far from ideal and can be quite a time-consuming task. A better solution to this problem is found in a plugin called Edit Flow.

Edit Flow is a complex plugin. It not only adds content notifications and review process, but also gives the ability to create custom status posts and groups for your users. There are also features appropriate for an online publications, such as an editorial calendar and a story budget feature. If you do not need all the features, the plugin allows you to only enable those things you require.

In this recipe we look how the Edit Flow plugin can be used to create a manageable editorial workflow for content creation on your site.

Getting ready

To execute this recipe, you will need to install the Edit Flow plugin. You will need to install this plugin before you can get started. Search for Edit Flow inside the Add New Plugins screen of your WordPress site. After you find it, click on it to install, and then activate it.

Note

You can learn more about the plugin by visiting the developer's website at http://editflow.org/

How to do it...

Let's start out by configuring Edit Flow for basic article submissions and a review process:

  1. Log in to the WordPress Dashboard.

  2. Click on the new menu named Edit Flow.

  3. On the configuration screen, de-select Enable Edit Flow Calendar and Enable Story Budget. Also select the option Always Notify Admin.

  4. Click on Save Changes.

How it works...

You now have a basic editorial review process in place, with notifications being sent to the site admin every time critical actions occur. The plugin has automatically added a set of custom statuses for your posts and pages. Click on the link Custom Status to see the list. The plugin has also created new usergroups. View the groups by clicking on the Usergroups option in the Edit Flow menu.

Taken together, the changes allow a site user (assuming they have permission to create content!) to submit an article for review. Notifications will be sent to higher-level users, who can then log in and comment privately on the content of the posts. When comments are made, the author is notified. This process can be repeated as many times as necessary. Once the post is ready for publication, the status of the post can be changed to published, thereby completing the editorial cycle.

When you log in to the dashboard, a new Edit Flow widget shows you a list of the posts in the editorial process, as shown in the following screenshot:

There's more...

As the next screenshot shows, the editing page for each post now contains several extra field:

  • The Editorial Comments field is where the editors can comment privately on the post for the author's benefit.

  • The Notifications Subscriptions section allows you to specify who will receive notifications and can avoid your site editors and admins from being bombarded with unwanted e-mails.

  • The Editorial Metadata fields give you a way to capture useful information about the post for your internal records. These fields can be customized from the Edit Flow menu.

See also

  • Managing users section in this chapter

  • Gaining control over user roles and permissionssection in this chapter

 

Importing and exporting content


WordPress features a very useful script to import your posts, comments, and links from another platform to WordPress. The system also allows you to export your current blog content.

Getting ready

Everything you need to complete this recipe is included inside the WordPress dashboard. Note, however, that while the WordPress import function is included in the dashboard, you will be prompted to download individual importers.

How to do it...

WordPress supports the importation of blog content from several other platforms, including Blogger, Blogroll, LiveJournal, MovableType, and TypePad. It also makes it easier to import posts saved from another WordPress site. The functionality also includes options to help import categories, tags, and RSS feeds.

By way of example, let's assume you wish to import content from a LiveJournal blog site. Follow these steps:

  1. Connect to your old blog and export your content. Save the file on your hard drive.

  2. Log in to your WordPress Dashboard.

  3. Click on the Toolsmenu.

  4. Click on the option Import.

  5. On the page that loads, you can select the type of import. In this example, we're going to select the option LiveJournal.

  6. The system will now prompt you to install the LiveJournal import plugin. Install the plugin and activate it.

  7. Once done, input your LiveJournal Username and Password on the fields provided, as shown in the next screenshot.

  8. You're done! Please note that depending on your exported file size, this procedure can take a while.

The system will now attempt to import the posts and add them to your WordPress site.

Note

The process used for a LiveJournal import is typical of that used by all the import options. If you wish to import from a system not listed, check the WordPress plugins listings at www.WordPress.com.

Exporting content is also quite easy; simply carry out the following steps:

  1. Log in to your WordPress Dashboard.

  2. Click on the Toolsmenu.

  3. Click on the Export option.

  4. Select what you wish to export and click on the appropriate radio button, as shown in the next screenshot.

  5. Click on the Download Export File button.

The system will then prompt you to save the export file.

 

Installing and using Jetpack


In early 2011, Automattic released Jetpack, a cloud-based suite of extensions for the WordPress CMS. Jetpack's features are based in part on functionality users of www.WordPress.com have enjoyed for some time. The modules include:

  • A site traffic statistics function

  • A LaTeX plugin

  • A spellchecker

  • A Twitter widget

  • A shortlinks functionality

  • A social sharing mechanism

  • Easy embeds from video and media sites

Additional functionality is in the pipeline.

While some of the features of Jetpack are also available in other plugins, Jetpack is a quick and easy solution from a known solutions provider.

In this recipe, we look at installing Jetpack and getting it up and running.

Getting ready

To execute this recipe, you will need to install the Jetpack plugin. You will need to install this plugin before you can get started. Search for Jetpack inside the Add New Plugins screen of your WordPress site. After you find it, click on it to install, and then activate it.

Installation requires a slightly different approach than for most other plugins. To use Jetpack, you must be a registered user on www.WordPress.com. As the next screenshot shows, you will need to use your www.WordPress.com credentials to activate the plugin:

How to do it...

After you have installed Jetpack and authorized it with www.WordPress.com, you will see the Jetpack Dashboard, as shown in the next screenshot. Before you can start using the features, you will need to do a bit of configuration, as follows:

  1. To begin using any of the features, first click on the Learn More button.

  2. The module will now be activated; if you don't want to use it, click on the Deactivate button.

  3. Some modules will present you with a Configure button, indicating there are customization options available. Click on the Configure button to learn what options are available.

  4. Some items, such as the Twitter Widget, are actually controlled in a separate location.

Once Jetpack is installed, a link to the Jetpack settings page is always visible at the top left of your WordPress dashboard. A separate link will show you the site statistics, assuming you have activated the feature.

Note

Site statistics and the WP.me shortlinks functionality are also available from the front-end, if you have installed the admin toolbar for the front-end of the site. See the next recipe for a discussion of the admin toolbar.

How it works...

While some of the features in Jetpack are simple plugins, other features rely on a cloud-based approach to services. Both the stats and the shortlinks functionalities need a connection to the Internet and to www.WordPress.com.

There's more...

WordPress Popular Posts is a separate plugin that uses the information gathered in the Jetpack stats module. The plugin provides a nice and configurable widget that shows a list of the most popular posts on your site.

Note

Learn more about the plugin by visiting the developer's site at http://polpoinodroidi.com/wordpress-plugins/wordpresscom-popular-posts/

 

Enabling the toolbar for users and administrators


One of the new features included with version 3 of WordPress is the Admin Bar . The bar is a menu bar that sticks to the top of the page and is always visible. It can be activated for either the front-end, the back-end or both. The bar contains shortcuts to the Admin dashboard and to various administration functions, depending largely on the user role of the viewer.

This recipe shows you how to enable this useful feature for your site users.

Getting ready

Everything you need to complete this recipe is included inside the WordPress dashboard. Note, however, that while the WordPress import function is included in the dashboard, you will be prompted to download individual importers.

How to do it...

This feature is not enabled by default, so you need to set it up for your users. Here's how to do it:

  1. Log in to the WordPress Dashboard.

  2. Click on the Users menu.

  3. Click on the name of the user for whom you wish to enable the Admin Bar.

  4. On the user Profile page, look for the option labeled Show Admin Bar.

  5. Select whether you want to user to see it on the front-end, the back-end, or both.

  6. Click on Update Profile.

About the Authors

  • Ric Shreves

    Ric Shreves is a web applications consultant and tech author. He’s been building websites since the mid-90s and writing about tech for almost as long. Ric specializes in open source content management systems and has written texts on each of the big three: WordPress, Joomla! and Drupal. Ric is the founding partner of water&stone, a digital agency that focuses on new media and online marketing. He works with clients on digital marketing strategy and supervises the SEO implementation team. Ric lives in Bali and divides his time between the island and Singapore.

    Browse publications by this author
  • Jean-Baptiste Jung

    Jean-Baptiste Jung is a self-taught web developer, web designer, and blogger. Jean is pretty active in the WordPress community and the Internet in general, blogging on his blogs CatsWhoCode.com and WpRecipes.com, as well as writing for prestigious blogs as such as Smashing Magazine.

    Browse publications by this author
Book Title
Access this book and the full library for FREE
Access now