Tag Archives: Wordpress

Multi-line Captions in WordPress

As my wife and I were each posting our daily photos this afternoon, she asks me to help her put a two line caption under one of her photos. Being somewhat knowledgable about such things, I tell her that I’d be happy to help. And what should have been a very simple task, turned into an hour and a half of messing around and re-writing the captioning capabilities in WordPress. Let me start with a little background. First, let me acknowledge that WordPress is a great blogging platform for text. And I have seen some really beautiful photography blogs created on this platform. But what most people don’t realize is that these photo-blogging themes have a ton of custom code. Out of the box, WordPress is still absolutely awful with regards to text mixed with media. And I do realize that they’ve been constantly updating things, but it’s frankly still a crude environment. The multi-line captions are a good example. While WordPress 2.5 added the ability to have captions, instead of building it into the user interface and allowing the user / writer to create content to be used as a caption, they instead decided to have the photo import interface add an odd caption shortcode which WordPress will later replace with actual HTML. What this means is that unless you want to modify WordPress core files (a very bad idea since you’d have to do it every time you upgraded WordPress), you’re stuck trying to fix captions within the bounds of their already lacking system. So, without further rambling, here’s the long and the short of fixing the captioning system (a little bit).

Current Implementation (WordPress 2.5+)

Before fixing the captions, we need to understand exactly how it works out of the box.  When you go to insert a photo into a post, if you type anything in the caption dialog, WordPress will insert an image surrounded by a “caption” shortcode.  It goes through and replace this caption shortcode with actual HTML when it’s requested by a reader. However, instead of taking a block of text and including it, all it takes is one lousy string that can’t have anything but text.

Allowing Multiline Captions

Due to the existing implementation, there is really only so much we can work with. We need to take the caption and break it into multiple lines, but remember, WordPress won’t store more than a string for the caption. To fix this, I decided that I’d insert line breaks into the caption based on a text string — in my case, I chose the “|” symbol as I don’t ever see it being used in a caption. You can replace it with whatever you like. To override the existing caption code, edit your theme’s functions.php file and add the following code (note, clicking on the left-most button in the top right of the code box will open the source in an editor — perfect for copying and pasting).

Please note, this will not work when inserting images in the WordPress Gallery format.

/* ********************************************* 
Function to allow multi-line photo captions. This function will 
split captions onto multiple lines if it detects a "|" (pipe) symbol. 
********************************************** */ 
/* Override existing caption shortcode handlers with our own */ 
add_shortcode('wp_caption', 'multiline_caption'); 
add_shortcode('caption', 'multiline_caption'); 

/* Our new function */ 
function multiline_caption($attr, $content = null) 
{ 
    extract(shortcode_atts(array( 'id' => '', 
                                  'align' => 'alignnone', 
                                  'width' => '', 
                                  'caption' => '' ), $attr)); 
    if ( 1 > (int) $width || empty($caption) ) 
        return $content; 
    if ( $id ) $id = 'id="' . esc_attr($id) . '" '; 

    $new_caption = str_replace("|", " ", $caption); 

    return '<div ' . $id . 'class="wp-caption ' . 
           esc_attr($align) . '" style="width: ' . 
           (10 + (int) $width) . 'px">' . 
           do_shortcode( $content ) . 
           '<p class="wp-caption-text">' . 
           $new_caption . </p></div>'; 
} 

With this done, all that was left was to edit the caption of the desired photo with something like this: “First line of caption.|Second line of caption”.

Additional Resources

In searching the web for a solution, I found everything but what I needed. However, I did find some good resources for WordPress captions in general.

What is SEO and why do I need it?

Looking around at numerous other blogs I frequent, it becomes painfully clear just how little many people understand about SEO, or Search Engine Optimization.  In this situation, ignorance is not bliss as these blogs are potentially sacrificing a large number of readers who can’t find the content contained within.

What is SEO?

SEO, or Search Engine Optimization is the process by which the author of a web page (or blog in our case) organizes and formats their content to make it more accessible to search engines such as Google, Yahoo, or Bing.  This sounds relatively simple, right?  Well, let’s start off by making it clear that there is no such thing as a blog with perfect SEO simply because there is no 100% definition of exactly what “perfect SEO” really entails.  However, there are a few simple things that can go a long way to making sure that your blog is at least getting indexed by search engines. Continue reading

Rookie Blogging Mistakes

In reading through Pro Blogger today, I found an interesting post entitled Rookie Lessons for New Bloggers, which was a guest post by Katie Kimball of Kitchen Stewardship.  As somewhat of a rookie myself, I decided to quickly jot down my thoughts.  This soon turned into the following full post which I figured I’d share with you all.

Blogging is Difficult!

Blogging - Hard Work

Photo by nkzs - stock.xchng

There.  I said it.  Blogging is difficult.  Even more so for someone new to online publishing — the “blog rookie” if you will.  Sure, there are tons of success stories, and great resources with tons of information.  That’s enough, right?  Perhaps.  But don’t be fooled into thinking it’s easy to sit down and write a successful blog!  The process of simply setting up a blog can be intimidating and time consuming, especially if you’re trying to setup a unique domain name and host the blog on a server as opposed to going through a ready made blog site such as WordPress.com or Blogger.  We haven’t even begun to write yet, a task which for many, is harder then they anticipated.  After an initial burst of energy and great ideas, finding topics, images and motivation can become difficult.  And we’re not even to the part of this venture where you have to actually market your blog.  That’s right.  Sites don’t just take off and become profitable on their own.  Along the way, mistakes are made.  Lots of them.  Yes.  Everyone makes mistakes when blogging and anyone who claims they haven’t is lying to you.

Continue reading

WordPress for BlackBerry

I’ve wondered for some time when today would come! Yes, sure, it’s been possible to post blog entries via email for quite some time, but as of today, there is an official BlackBerry WordPress client that works over BlackBerry Internet Service (BIS)!

So, what’s so great? Check out this video demonstration for a quick overview!

Yes, this app has been around for a couple months, but the BIS support they added in todays release really makes it usable for the general public on the go (prior versions only supported BES – BlackBerry Enterprise Server, a corporate setup).

So if you have a BlackBerry, check it out by pointing your browser at http://blackberry.wordpress.org/install to give it a try. You will need to have XMLRPC installed and working properly for this app to work, but the latest versions of WordPress have this working out of the box (unless your theme doesn’t support it).

It works great for me, so let me know how it’s working (or not working) for you. And yes, this whole post was written on my BlackBerry Bold!

New Theme on Digitalnotions.net

As some of you may have noticed, the theme on Digital Notions has been completely overhauled! While the individual pages might not look too much different, the homepage is completely different as you can see from the image of the old theme below!

I’m still perfecting some of the details, but the new theme offers a much better user interface (I believe) and will hopefully not limit the future growth of this site. I’m trying to focus more on the articles and devote less time to messing around with the code behind ever single post. I’m also hoping that I’ve improved the comment interface so hopefully, it will be easier to leave your thoughts.
Continue reading