Archive Page 2

Akismet, Akismet, Akismet

Akismet is a fantastic service that does only one thing and does it very well — it fights comment spam. Their homepage, however, is full of various keywords that dilute that simple message:

Here are a few things that are wrong with this design: dictionary definition cliche; why is the spam count so prominent and has two versions — I bet that most people can’t even pronounce that number; too many words to explain a simple idea.

Here is a suggested re-align:

Self-hosted HTML5 Notepad App With Synchronization

Ever since the days of Google Gears which enabled local storage and offline syncing for online applications such as Google Reader and Docs, I have always wished for a very simple and instantly accesible notepad application that I could host on my server and use also without an internet connection. A place where I could instantly write down an idea or paste a link or a quote from an article.

Google Docs and Evernote is great but they have way more features than I would normally use. WordPress is fine, but it takes several steps to get to the actual writing, and you must be connected to the internet to use it.

The Solution

Now that we have HTML5 with support for localStorage and offline apps in all of the modern browsers, it seems to be the perfect solution. All that is needed is a little PHP script that synchronizes the content of localStorage with the server. Here is how it looks:

You have your files on the left and a very big plain text editor on the right.

How Does it Work

The app consists of the following:

  • One HTML file with enabled offline access (cache manifest).
  • jQuery for all the Javascript and AJAX magic.
  • One PHP file with HTTP authentication for syncing with the server.

The files are stored in browser’s localStorage as key/value pairs with a unique timestamp ID as key and JSON formated content as value. An index of all files and their version timestamps is kept and used for synchronization during which all the content of localStorage is sent to sync.php in a POST request. The server reads its own index file and determines which new or edited entries need to be stored and which returned to the browser. All entries are stored on the server as JSON strings in simple text files.

Demo, Download and Installation

Please visit the project page of the HTML5 Notepad App. There is also a sample Chrome app.

Remove Inline CSS and Line Breaks in WordPress Galleries

Inline CSS and line breaks <br style="clear" /> that are automatically added to the image galleries in WordPress is an example of how the needs of Automattic and WordPress.com influence the way new features are added to the WordPress core. So instead of editing every single theme on WordPress.com and adding the necessary CSS for galleries to look good in all of them, they decided to put it WordPress core.

Here is how to replace those double line breaks with a single <br /> and remove the inline CSS:

add_filter('the_content', 'remove_br_gallery', 11);
function remove_br_gallery($output) {
	return preg_replace('/(<br[^>]*>\s*){2,}/', '<br />', $output);
}

add_filter('use_default_gallery_style', '__return_false');

Replace WordPress Login Logo With Your Site’s Name and Link

There are several plugins out there that allow you to replace the WordPress logo on the login screen. Here is a simple way to replace that logo with your site’s name — place this in your theme’s functions.php:

add_filter('login_headerurl', 'my_login_url_local');
function my_login_url_local() {
	return get_bloginfo('url');
}

add_filter('login_headertitle', 'my_login_title_attr');
function my_login_title_attr() {
	return esc_attr(get_bloginfo('name'));
}

add_action('login_head', 'my_style_site_name');
function my_style_site_name() {
?>
	<style type="text/css">
	h1 a { width:auto; height:auto; text-indent:0; overflow:visible; text-decoration:none; color:#666; display:block; margin:0; padding:0 10px; background:none; }
	h1 a:hover { color:#000; background:none; }
	h1 { font-family:'helvetica neue', arial, sans-serif; font-weight:bold; text-align:center; font-size:2em; width:310px; position:relative; right:-8px; margin:0 0 1em 0; }
	</style>
<?php
}

Here is how it will look:

Add rel Attribute to Image Links in WordPress Galleries

If you want to use either Fancybox or Lightbox scripts for image galleries, you need to add the rel attribute to all full size image links. Here is how to do it:

add_filter('wp_get_attachment_link', 'add_gallery_id_rel');
function add_gallery_id_rel($link) {
	global $post;
	return str_replace('<a href', '<a rel="gallery-'. $post->ID .'" href', $link);
}

We simply replace <a href with <a rel="gallery-n" href where n is a unique post ID. This filter is applied in /wp-includes/post-template.php.