Add a Page Select to the Customizer

I’ve been working on a new theme that allows users to select certain pages in the customizer, and then display those pages out on a “showcase” template. I think this is pretty useful functionality and wanted to share how I implemented it.

Add Settings, Controls and Sanitization

First, we’ll need to the page select boxes to the customizer. In the code below, I add a new customizer section called “Showcase”. Then, I loop through the add_setting / add_control functionality in order to display four distinct page select boxes.

I’ve also created a function called “prefix_get_pages_array” which returns an array of all the pages to be used both by the controls and the sanitization function. You’ll notice it sorts the pages alphabetically, and indents sub-pages slightly with an em dash when output in the select box. Continue reading

How to Disable Comments in WordPress

It’s surprisingly difficult to disable comments globally in WordPress.

Comments can be turned off for new posts in “Settings > Discussion” screen. However, all previously published posts would still retain their comment settings and need to be disabled individually under the “Discussion” metabox on the post edit screen (which can be very time consuming).

Disable Comments with One Click

The easiest way to turn off comments globally is actually with a plugin called “Disable Comments”, which is a free download from wordpress.org.

disable-comments

After enabling the plugin, you can choose to disable comments everywhere or only for specific post types. If you want the changes to be permanent, choose the “persistent mode” option before saving.

If you have chosen to make the changes permanent, the plugin can be deleted after you save the settings.

Deleting Comments

If a site was abandoned for a while or suddenly got hit by a lot of comment spam, you might want to delete all the pending comments or spam comments. For both of those scenarios, you can use a plugin called Delete Comments By Status.

Delete Comments By Status also allows you to delete “trash” comments and “approved” comments in bulk.

After enabling the plugin, go to “Settings > Delete Comments”.

Link to Customizer Sections

One neat “feature” introduced in WordPress 4.1 was the removal of the background and header admin screens in favor of the customizer (see ticket). Now if you click to customize one of those items, it links directly to the customizer and opens the appropriate panel.

If your plugin or theme adds customizer options, you can also link to those. Just use:

admin_url( 'customize.php?autofocus[control]=control-name' )

Replace “control-name” with the name of the control you’d like to link to. Continue reading

Faster Image Loading with Jetpack & Photon

Photon is a JetPack module that enables your images to be resized and loaded using WordPress.com’s servers. This can can speed up the loading of images for several reasons:

  • Photon utilizes multiple levels of caching, including a globally distributed CDN to make sure images are served as fast as possible.
  • Lossless compression. All images are losslessly compressed using either OptiPNG or jpegoptim.
  • Photon takes advantage of parallel downloads by using multiple sub-domains to load images.
  • Images are resized if they exceed the max $content_width set for theme.

Read more in the Photon Developer Docs.

Adjust Image Quality

However, you might be able to squeeze your image sizes even further by using the Photon filters to adjust the quality. Instead of loading images at full quality, you could try 80%. Continue reading

Excerpt versus Content for Archives

Most theme developers have slowly moved away from using the_excerpt to display content on index, archive and search pages. I definitely have.

Let’s go over quickly how the_excerpt works:

  1. If an excerpt is explicitly defined, it will be displayed (including HTML).
  2. If an excerpt isn’t defined, the post content will be used, but stripped of HTML and truncated to 55 words by default. An indication that is has been truncated also displays “[…]”.

If a post consists entirely of a YouTube embed, a gallery, a single image, or a Tweet embed, “the_excerpt” will strip all that out- and thus nothing will be displayed. This makes for a very weird looking archive page if the_except is used.

The alternative is to use the_content. This allows the full content to show. But the content can also be truncated on archives by using more tag.

This is what I’ve been using in most of my new themes as it is the most flexible. Continue reading

Announcing Hexagone

2015 will be a transformative year for language support in WordPress. The majority of new WordPress installs are now in languages other than English. New APIs are in the works for wordpress.org which should make translation easier, and new features in WordPress core will add better support for those languages. But what I’m really excited for is the eco-system in those other languages to grow.

Matt Mullenweg alluded to this at WordCamp Europe, “Personally, I am far and away most excited about the internationalization improvements, because the fact that WordPress has that many users at all in these other languages where there’s not very much documentation, no plugins, very few themes, it’s kind of amazing.”

Which brings me to a new project I’ve been working on with a partner based in France… Continue reading