robinadr

Smarter Archives 3.0

December 20, 2013

Although version 2.6 was just released less than a month ago, I’m proud to announce the release of Smarter Archives 3.0. As the version number would suggest, this is a major update.

I’ve completely rewritten the code while maintaining backwards compatibility, resulting in more streamlined code, and also reducing the total number of database queries used to 1. As in a single query. More on the code differences can be found later in this post.

Go to the plugin page to download it now, or upgrade from within your WordPress dashboard.

Continue reading “Smarter Archives 3.0”

Google Prettify + WordPress

December 16, 2013

I have been using SyntaxHighlighter Evolved to highlight code on here for a while, but it always had problems playing well with the Markdown plugin I use. I wanted to change to something that falls back gracefully, and doesn’t require any special markup outside of what Markdown can do.

I ended up using Google Code Prettify to highlight my code. It doesn’t use any weird markup (just adding a prettyprint class to the <code> block, and I can do all of it in Markdown. Here’s an example of a code block:

~~~ {.prettyprint .lang-php}
<?php
// Source code here
print( "some string" );
?>
~~~

The above Markdown ends up rendering like this:

<?php
// Source code here
print( "some string" );
?>

Because it doesn’t use any strange or custom tags (just a class on a <code> block), it will degrade gracefully into just a regular <pre> block without highlighting if the Prettify code disappears or isn’t working. To me, this is a much better solution than a [shortcode] like the ones that SyntaxHighlighter Evolved uses.

Here are the 2 lines of code that make it all work:

<script src="//cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.js"></script>
<script>prettyPrint()</script>

Conflicts with WordPress

If your theme makes use of it, WordPress adds classes to the <body> tag through the body_class() template tag. Unfortunately, on some pages, these classes can sometimes conflict with the global styles used by the Prettify themes. For example, on my tag archive pages, the <body> tag had a class of tag, which is one of the classes Prettify uses to highlight code. The result was pink text everywhere on the page.

To fix this conflict, I edited my Prettify styles to change the scope of the styles to those classes within <pre> and <code> blocks. For example, this is the original style rule:

  /* a markup tag name */
  .tag {
    color: #f2777a;
  }

I changed it to this:

  /* a markup tag name */
  #content pre .tag {
    color: #f2777a;
  }

Shrink Your Jetpack Installation

December 12, 2013

The disk usage for my website shot up recently, and I couldn’t figure out why. I did some digging, and I found out that my plugins folder was 23 MB in size. How can this be? For reference, my entire website is only about ~48 MB, and that’s including this jump.

$ du -hd 1 | grep plugins
 23M    ./plugins

It turns out that this was all due to my Jetpack install:

$ du -hd 1 | grep jetpack
 21M    ./jetpack

As it turns out, the languages folder was 10 MB on its own:

$ du -hd 1 | grep lang
 10M    ./languages

So I deleted the following files and folders: languages, tests, phpunit.xml, and readme.txt. My Jetpack folder is now down to a more reasonable 6.6 MB. It seems pretty sloppy to include the unit tests with a production release, but if you remember to delete these folders every time you update the plugin, you will save a lot of disk space.

Of course, if you actually need a translation, I would recommend deleting all the PO/MO files except for the ones you need.

The Gritty Taste of Pears

December 11, 2013

While eating a pear this morning, I found myself wondering why they have a characteristically gritty texture within the soft, juicy flesh. I did some quick research, and learned this:

Pears have a characteristically gritty texture caused by cells in the flesh called stone cells. Although more and more of these have been bred out, all varieties still contain them. #

It turns out these “stone cells” are examples of a sclereid, which are sclerenchyma cells that die at maturity once they form their lignin-reinforced cell walls. In fact, the volume of these cells are comprised of mostly the cell wall itself. Lignin is a tough material that plants use to reinforce their cell walls and is what makes the stone cells seem like small grits in your mouth.

Smarter Archives 2.6

November 30, 2013

Smarter Archives 2.6 is now available to download from the WordPress plugin repository. Big changes include internationalization support (with a Spanish translation included for now), the addition of a new shortcode, and the plugin’s options are now fully documented.

Now, instead of having to use a PHP call to use the template tag (dangerous if you use a runPHP-style plugin), you can just use the smarter-archives shortcode to include it anywhere. See the usage section for what options are available to customize the output.

Changelog

  • Standardized i18n calls — fully translatable
  • Added a POT file for translating
  • Added a lang folder
  • Spanish (es_ES) translation added — thanks to Andrew Kurtis of WebHostingHub
  • New shortcode: smarter-archives, see Usage for more details
  • Fixed bug: order now actually does something

See the complete changelog here.