Quick WordPress Tip – Building your own shortcode

Wordpress LogoThis is a bit of a break from my normal blogging, but I felt like sharing a quick self-hosted wordpress tip that others might find useful.

In my regular Foto Friday posts, I have a section of content that I copy and paste into each post that points readers to other areas to find my photograph on the web as well as ways to help me with my addiction habit of photography.

The text is:

See more photos in my flickr photostream and/or my 500px portfolio. If you like my photography, feel free to support my addiction habit by visiting Adorama (affiliate link) to purchase new or used photographic gear. Or, if you are interested in renting gear before buying, try out my favorite camera, lens and gear rental site –  Borrowlenses.com (affiliate link) – the folks at Borrowlenses are awesome.  All proceeds from clicking the above affiliate links go to more photographs. 

For each Foto Friday post, I would go back to the previous post and copy the text and then paste it into the new post. While not difficult, this was getting to be a chore for me….and I started wondering how to make it more automated.

I’ve built themes and custom functions for WordPress before so I knew about shortcodes….but hadn’t really used a shortcode for just adding text before…but I figured it would work just fine….and it did.

This is a fairly easy thing to do for those of you who are technically inclined.  All you need to be able to do this yourself is a self-hosted version of WordPress and access to your theme’s “functions.php” file – and some basic HTML (and perhaps PHP) knowledge.

Building a Custom Shortcode

I found my theme’s functions.php file a pulled it off my server to edit it.  Using Notepad++ (create free editor for Windows), I added the following lines:

[sourcecode language=”html”]
/* Add shortcode */
add_shortcode(‘phototext’, ‘addPhotoText’);
The above is the definition of the shortcode text to use. In the add_shortcode function, the first field ‘phototext’ is my actual shortcode text that I want to use in each post. The second field ‘addPhotoText’ is the name of the function that should be run whenever the shortcode ‘phototext’ is found. Pretty simple so far, no?

Now…the code below is the actual ‘addPhotoText’ function. The only thing I want this function to do is insert the HTML code listed below into a post whenever the ‘phototext’ shortcode is found.

[sourcecode language=”html”]
/* Function for added shortcode */
function addPhotoText() {
return ‘
See more photos in <a href="http://www.flickr.com/photos/ericbrown">my flickr photostream</a> and/or my <a href="http://500px.com/ericbrown">500px portfolio</a>. If you like my <a href="https://ericbrown.com/photography">photography</a>, feel free to support my <del>addiction</del> habit by visiting <a href="http://www.adorama.com?kbid=65146">Adorama</a> (affiliate link) to purchase new or used photographic gear. Or, if you are interested in renting gear before buying, try out my favorite camera, lens and gear rental site – <a href="http://www.borrowlenses.com/?blpid=photographyminute">Borrowlenses.com</a> (affiliate link) – the folks at Borrowlenses are awesome. All proceeds from clicking the above affiliate links go to more photographs.

Once the above shortcode and function have been added to the functions.php file, I uploaded the file to my test server to make sure i didn’t fat-finger something. Once the new shortcode was confirmed to work, I moved it over here to my blog.

So now…anytime i type my shortcode phototext wrapped in brackets (a shortcode is wrapped in brakcets – e.g., [shortcode]), I’ll get the following added to any post/page:

See more photos at my dedicated Photography website. If you like my photography, feel free to support my addiction habit by purchasing a copy for your wall and/or visiting Amazon (affiliate link) to purchase new or used photographic gear.

Shortcodes make life much easier for WordPress users. If you have some content that you like to re-use (author bio, etc), take a look at using shortcodes…they may save you time.

BTW – If you have any questions about WordPress, shortcodes or anything else, drop me a line and I’ll see what I can do to help.

WordPress as Web Framework

WordPress logoAs you know, I love WordPress.

I use WordPress for everything these days. This blog runs on WordPress. My photography blog runs on WP.  My wife’s photography websites (a moment to keep photography and Boudoir Moments) run on WordPress.  Like I said…everytime I build a website today, I start with WordPress if I can.

So…when I was asked to help build a new website for Silicon Valley Expert Witness Group, an intellectual property consulting and expert witness services firm, I jumped at the change to use WP.

Jump over to www.svewg.com and take a look at the site. Does it look like a blog?  Nope.   It looks like a website. It’s a website.  We used the new Custom Post types found in WordPress 3.0 for the expert bios and added some interesting functionality to the site.

Does WordPress make sense for all organizations?  No…but its worth a look to see if it can work for you.    The open source approach (and community) that WordPress has allows you to build whatever you want to build.

WordPress has moved from a ‘blogging engine’ to a ‘website framework’….take a look at it for your next web project.

I. Love. WordPress.

Wordpress LogoSorry for the silly title…but I do I love WordPress.

Well…I should clarify…I love the self-hosted version of found at WordPress.org).   The WordPress.com version is quite good but you lose the ability to do some customization over there (unless you’re on the VIP platform…and you’re still limited in what you can do there).

Why do I love WordPress?

It’s so much more than a blogging platform.  It’s really a framework.  It’s a framework for building websites.

Take a look at my site.  It’s built on WP using the Genesis Theme Framework (affiliate link) which I’ve customized to meet my needs. I added a customized version of the WP Featured Articles Slider to the front page to highlight previous articles.

Could I have done this with other platforms?  Sure.  Would it have been free? Perhaps.  Would it have been easy (given you know a little web design/development)?  Maybe.

But…every other platform I’ve used in the past would have required much more development to get the basic structure built.  I could have used Drupal or Joomla but neither of them are as easy and straightforward as WordPress is for me.

The real strength comes from the Theme developers like StudioPress (the folks behind Genesis), Thesis or Headway. With these frameworks, you can really extend the power of WordPress as a platform.

Personally, I’m a fan of Genesis due to the ability to build child themes for customization. These child themes allow the core Genesis framework to be upgraded without affecting the custom design / functionality.    I love the genesis framework so much I decided to customize one of the child themes to rebuild my Photography Minute photo blog.

WordPress…for more than just blogs

But…WordPress can be used for more than just an individual’s blog / website.

For example…take a look at the Boy Scouts of America’s Boys’ Life website.  It’s built on WordPress and hosted with the VIP program.  I’m happy to say that I was a part of the team that built the site last year….it was quite a learning experience for me and an eye opener to the power of the WordPress platform.

On first glance, that doesn’t look like much like a blog does it?  Doesn’t to me.   Lots of really cool stuff happening over there with a mixture of PHP, Flash, jQuery and Javascript…really cool stuff for us tech geeks 🙂

In addition to my own blogs and the work on the Boys’ Life website, I’ve been working on building a new website for Silicon Valley Expert Witness Group using WP as a Content Management Systems (CMS) for the underlying technology to run the website.  That site (planned go- live in early Sept 2010) is using a ton of custom development and Custom Post Types to handle the hundreds of Expert Witnesses and litigation consultants listed on the website as well marketing and corporate information.

I’ve got another stealth project going right now that uses WordPress, a Custom Theme and the PHPurchase shopping cart plugin to manage sales and subscriptions. Still putting the finishing touches on that project…maybe I’ll talk about it more in the future. 🙂

I’m finding WordPress to be an extremely flexible and wonderful framework to build websites with.  Not only do you get WP and themes, but a ton of developers and help from other WP developers and users. The power of Open Source in action.

PS – If you’re looking for a WordPress Developer or Designer, let me know … I’ll be happy to recommend a designer to you and might be able to take on the development efforts myself … if I can’t help, I know a few folks who can.

Most Commented Articles for 2008

I recently installed IntenseDebate on my blog and started playing around with the tools available to me.  I noticed that I can easily stats of posts and comments…something I hadn’t really looked at before.

What are my most commented posts from 2008?  See below.

In addition to the top commented posts, I can now see my average ‘comments per post’…which is a measly 0.89 comments per post.   This is a bit strange since I’ve got 655 comments on 314 Posts…which should be 2.09 comments per post.

After reviewing some of the data, I noticed that IntenseDebates’s numbers are for comments only and not trackbacks (which makes sense).  With that knowledge, I guess I’m getting 0.89 comments per post and 1.2 trackbacks per post.

Its amazing that a rant I posted about Blu Domain’s horrible customer service is my number one commented post.

Reblog this post [with Zemanta]

Blog Updates – Theme Change & IntenseDebate

Its that time of year again.  No…not the holidays.  It’s time for me to change my blog around again 🙂

I’ve changed the theme to the Contender Theme and added IntenseDebate to handle comments.

Let me know if you see any issues with the blog and commenting system.

Reblog this post [with Zemanta]

Technical Difficulties

I had some technical difficulties today with my website…I changed hosts and it looks like I’m having problems with the DNS changes propagating…I think everything is well now.

Also…just upgraded to WordPress 2.5…some functionality isn’t working (popular posts mainly) but I hope I can get it back at 100% shortly.

If you'd like to receive updates when new posts are published, signup for my mailing list. I won't sell or share your email.