Puzzled Web Designer Asks Savvy Audience Burning Question

I’m losing sleep over this.

Picture yourself as the client: you want a special piece of content to appear on every page of your site. It’s going in the header, after every blog post, or in the footer. Something cool.

There are three ways to do this, which you’ll see below. The goal is to make the content easy to transfer from a development sandbox to a live environment while keeping it easy to edit for the client. What’s the best way?

Option 1: Create a file

Let’s say you’re adding social sharing to the end of your posts. You create a file called sharing.php, plop your sharing code in it, and tell your WordPress theme to “require” that file at the end of each single post. Seems fair enough, right?

The good:

  • A PHP file (surprisingly enough) accepts PHP syntax. You can do all kinds of cool stuff.
  • You don’t have to fight formatting. A double hard return doesn’t automatically create a new paragraph
  • You can seamlessly transfer this content to a live instillation; the content moves with the theme.
  • The content is always backed up since it’s accessible as a physical file. You don’t have to worry about it mysteriously disappearing.

The bad:

  • The client can’t easily edit it. Period. (This is huge.)
  • As you add extra files to your theme, the directory loses its elegant simplicity. Your visitors will never see nor care about this, but I strongly believe that as true artists, it’s our responsibility to beautify the invisible.

Option 2: Create a widget

Widgets are incredible. You can make a widget out of literally anything on your site. I’ll confess to you: I have eleven widgets on this site, and they’re awesome.

The good:

  • With just a few lines of PHP in your themes’ functions.php, you can enable PHP syntax in widgets.
  • Again, you don’t have to fight formatting.
  • Clients can easily edit their content.

The bad:

  • You have to manually copy and paste widget content from one instillation to another
  • You have to manually back up your content.1

Option 3: Create a page (!)

Stop laughing. I know a *very* expensive web agency that utilized this option. Here’s how it works: you create a page, grab its ID, and “query” that page wherever you want it to appear. Back to our original example, you could pop your social sharing code into that page and query it for each end-of-post area.

The good:

  • The client can easily edit this.
  • You always back this up whenever you back up your database. It’s not going anywhere.

The bad:

  • Enabling PHP ain’t easy without a plugin, and you should avoid plugins like fire.
  • You’re constantly battling WordPress’ automatic formatting, which gets in the way.
  • These pages have their own URLs, so you have to block search engines (including your site’s own search) to keep viewers from finding them.

What’s your verdict?

How would you solve this problem?


1 This assumes you’re transferring the database through the WordPress console. While it is possible to preserve the widget text by transferring the MySQL database through the PHPmyAdmin interface, this doesn’t solve every scenario. Since web designers often redesign sites, they’re not transferring databases – they’re simply uploading and activating new themes.

Comments

  1. Sarah says:

    This is a very good question, and amazingly something I’m trying to solve now! I’m building a site in WordPress and need to allow my client to edit some contact information which will appear in the footer. Currently it’s an address, two phone numbers and an email address (which will obviously need to be a mailto link). I’m trying to see if I can create an options/settings page for my theme which will allow my client to edit this information in a textarea field – preferably the standard WordPress WYSIWIG editor. I haven’t sussed it yet, though, so I’ll be watching this post’s comments for more ideas to try!

    • Martyn Chamberlin says:

      Hmm … not sure how you’d integrate the WYSIWYG editor on the actual settings page. If it was me, I’d just use option #2 or #3. But if you figure out something cooler, let’s definitely hear. ;)

  2. elliott f. says:

    i personally would go with either a page that has some custom fields on it (to get around the formatting problem), or i would create an “options” panel in my theme. i’ve seen some premium themes that use them, and it seems like the best way to go.

    http://net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/

  3. Bryan says:

    It seems like the third option is the best. The client has to be happy. Making things as easy on them as possible goes a long to toward that goal. The formatting might not be perfect, but if the client wants the feature that badly, they should be aware of the tradeoff. Also, would one plugin to enable PHP be that bad? Would the client even notice a performance hit?

    As for blocking search, couldn’t you create a subdomain for the page to help sandbox it a little better?

    • Martyn Chamberlin says:

      Naw, it wouldn’t be that bad a performance hit. I’m just paranoid with plugins. ;)

      The subdomain possibility is interesting, though I don’t quite follow. Would the subdomain point to a different IP address?

      • Bryan says:

        I was thinking you could put a robots.txt file in the subdomain folder, and that would keep search engines out. But now that I think about it, I don’t think you can tell WordPress to put a page/post in a separate folder/subdomain. So there goes the easily editable aspect unless you create a separate WP instance, meaning the client would have to remember to log into a different place to edit.

        Are you using Genesis with this client? If so, can’t you initially create the page for the client, check the noindex and noarchive boxes in the “Robots Meta Settings”, and then let them edit the content themselves?

        Then you can add a function to the functions.php file to exclude that page from WP search ala:

        http://wordpress.org/support/topic/excluding-page-from-search#post-1506663

  4. I’ve used the third option the most and it’s not a ridiculous idea at all. I totally recommend it for the same reasons you mentioned.

    I’ve also found that you can do it with a post and keep the post private (in most themes, this means it won’t be read by search engines, or seen in the blog feed). Then you just have to query the post ID and you’re set.

    • Martyn Chamberlin says:

      Interesting point, Preston. I’d use a post instead of a page too, since you don’t want to clutter the pages with “fake” ones.

      Regardless of your theme, it’s not that hard blocking posts from your blog home and RSS. Create a category called “hidden”, replace "6" with its ID, and paste this in your theme functions:

      function exclude_category($query) {
      if ( $query->is_feed || $query->is_home ) {
           $query->set('cat', '-6');
           }
      return $query;
      }
      add_filter('pre_get_posts', 'exclude_category');
      

      For example, all the links on my tutorials page are actually blog posts. It’s pretty cool. :D

      Thanks for weighing in! Interesting to see other people are using this technique.

  5. Martyn, You’ve lost me with this one; I have no idea what’s better. :)

    In other news, are you wearing a bathrobe in your new picture? I can’t quite figure out what it is that you’re wearing… ;)

    (And that’s me voting for you to bring your old picture back)
    :)

    • Martyn Chamberlin says:

      I’m wearing a coat, but if you want it to be a bathrobe, that’s cool. Picture’s here to stay. :P

      I’m afraid I spammed about a thousand people in order to have an interesting conversation with half a dozen. Oh well. Derek told me I’d built the wrong list, and he was right.

      • To that end, I really like the depth of this discussion that you’re having about design. It’s a great turn for you. I look forward to more even though it’s way above my head. :)

      • Hi Martyn,

        Well, this post would have been a nice fit on genesis tech forums rather than a blog post. Because, not all your subscribers might be as tech-savvy as you. (myself excluded..I am a design addict ). :-)

        However, I am still going to be a subscriber of two hour blogger because I am looking forward to many artistic posts from the artist :-)

        Anyways. coming to the options, I personally like to suggest a widget.

        Simply because its easy to edit for the clients.

        As a designer or developer, it doesnot matter how complex it is for you to implement a feature, you shouldnot pass the complexity to clients. In facts clients even need not know how you are handling it (unless they read this post).

        Just document the steps and implement a widget :-)

        Widgets are great. They are already pumping oxygen to blogs.

  6. Hi Martyn,

    Like Joseph, I’m clueless on this topic. I must be one of your subscribers who landed on the “wrong” list you were building. :)

    At any rate, I haven’t been here in a while and I really like the new look. Change can sometimes be a good thing.

    Looks as though you’re getting a lot of really good feedback in the comments. That’s one thing I’ve always admired about you as a fellow blogger …

    You know how to “invite conversation”.

Speak Your Mind

*