Keir Whitaker - Publishing occasionally since 2008

Introducing WP-Blocks

I am currently putting the finishing touches to a new WordPress plugin called “WP-Blocks”. It’s a simple idea but one that I hope WordPress users will find useful.

The Problem

For most situations the WordPress “post” or “page” is sufficient for our content needs. They allow us to create and edit, via the admin interface, our content easily. However sometimes I find myself wanting to edit text or images that I have “hard coded” into the actual WordPress template, content that doesn’t easily fit into the “post” or “page” paradigm.

In order to keep my source “controlled” this involved editing my template, committing it to Git and then uploading the template to my server. For a small text change it’s a heavy process. Enter “WP-Blocks”.

The Solution

This plugin will enable you to define an infinite number of “content blocks”. You will then be able to edit these blocks via the admin interface using the rich text editor we are all familiar with.

In order to output these blocks all you have to do is add one function call to your template, a one time addition.

For example, to output a content block called “footer-notice” we would add the following to our template:

<?php get_wp_block('footer-notice'); ?>

Features

Here’s a quick roundup of what the plugin offers:

  • Infinite number of content blocks
  • Editable via the rich text editor
  • Template code displayed in the admin area for simple copying and pasting into templates
  • Turn the block “on” or “off” to show or hide depending on your needs
  • Ability to add a HTML wrapper to your block. This lets you define elements that will only appear if the block is active.

Potential Uses

I developed this plugin as I wanted to be able to edit the short biography in the sidebar. Here are some other ideas you could use it for:

  • Footer text, e.g. copyright notices
  • Updating your “I’m available for work” section on your portfolio site
  • Banners at the top of your site advertising a link or new site
  • Sidebar lists, e.g. events you are attending

Coming Soon

I am in the process of putting the finishing touches to the admin interface. This in itself is worthy of a post as it’s taken me some considerable time to wrangle the admin CSS into a usable form. I hope to release the plugin in the next few weeks.

If you would like to beta test the plugin please drop me an e-mail.

25 Comments

prisca

Keir, this sounds great :)
I’ve been plugging in custom blocks into WP for a while, usually hardcoded into the template, of course. Useful for certain situations but too rigid and quite useless in lots of others….
Sounds like your plugin will be perfect for all cases :) Looking forward to trying it out once it’s done :)
Good luck :)

Keir Whitaker

Hey Pricsa,

Thanks for your comment. There’s just a couple of things to iron out and a bit of work on the admin side of things to go so it should be out soon. Hope you will find it useful.

Tomg

Hey Kier, good call on this plugin. I had this exact problem t’other day: solved it with a second loop query that pulled in content from a specific category. I like your approach better tho.
Cheers

Bill

Hey Kier, I’ve been using this plugin which works in almost an identical way:

http://wordpress.org/extend/plugins/multiple-content-blocks/

However, I’ve encountered loads of bugs with the way it functions, and the new rich text editor blocks are not identical to the native WordPress version.

It’s a great idea that you develop this, much needed indeed. I’d love to help Beta test when it’s ready. Please use my email from this comment to contact when ready if you’d like.

Thanks!

Matt Hill

I couldn’t get this worka at all, it just output some PHP directly into my HTML. I couldn’t understand until I checked the source code: your PHP files in the “controllers” and “inc” subdirectories use the short PHP tag of “<?" — this fails on some server setups. If you change these so that they start with "<?php" it works fine.

Matt Hill

Once I got this working, I found it pretty cool. Can I make a couple of suggestions for enhancements?

1) Add an option to RETURN the content, so it can be used in a variable, rather than ECHOING immediately. I have a situation where I need to do a little processing on the returned content before displaying it.

2) Add an option for a “friendly” label for each of the WP-blocks list screen. At the moment, the label is the lower-cased slug and this isn’t as easy to read. For example, I have a WP-block slug of “next-film” — it would be nice for this to say “Next Film”

Cool little plugin, keep up the good work :-)

Keir Whitaker

Hey Matt,

Thanks for trying it out first of all and secondly for the feedback. I think you must have downloaded one of the early betas as I have fixed the short tag issue.

The best version to go for now is the version in the WordPress plugin repository. Full details on where to find it are in this post http://keirwhitaker.com/archive/wp-blocks-now-in-plugin-directory/.

I like the idea of returning the idea, happy to add that in. I will likely default it to echo but have an option to return it too. Adding in the “friendly name” would be relatively straightforward but would require a database change. I’ll need to look at how WP handles migrations. Alternatively I could just unslugify the name – what do you think?

Matt Hill

Hi Keir. That’s strange, I downloaded the version in the repository, directly through the Add Plugins page in my WP back end. It’s v1.2 Beta — this has the shortcodes problem in it.

Regarding slugs, I only mention it in case I were to use this plugin on a client site — I think friendlier label names would be required there. I don’t mind them being slugs on my own sites. But yes, perhaps if it’s possible just to “unslugify” (great word!) for label display, that would be cool.

Do you have a donations button? I can see this being very useful :-)

Keir Whitaker

Hey Matt, that’s very strange. I did another sanity check and can’t find any shortcodes in the version I have and it looks to mirror what I checked in to the repository.

I have just pushed it again so if you wouldn’t mind letting me know if the problem persists that would be great. Was it a particular page that it happened on?

I don’t think “unslugifying” should be too hard, let me look into that as the next “feature”.

Thanks for the suggestion of a donate link, I have added one here:

http://keirwhitaker.com/donate/

Matt Hill

Hi Keir. I tried updating to 1.3. It still has short PHP tags in your controllers/index.php file and inc/wpblocks.class.php files. If I run this version, I get the same problem as before: “do_action(); ?>” is output to the screen. I can manually fix up the short tags and the plug-in works fine after that.

Matt Hill

No problem, glad to be of help. I see you added do_shortcode to this version, I’d hacked my earlier version to do that too :-)

Victor Teixeira

It’s breaking the admin menu. I can’t make the menu parents slide down. Also breaking the Help and page options sliders.
I think it’s a jquery conflict.

Robert

I love this plugin. Thank you. I have been using the RB Internal Links plugin by Arron Woods which includes a button in the Visual editor for inserting internal links. However, when I activated the WP-Blocks plugin, the RB Internal Links button disappears.

Not sure if anyone else has had issues with this, but any ideas on how to get these to play well together?

Thanks.

Rein

Hey! I can’t get your plugin to work at all! When I click WP-Blocks in the admin, it’s empty!? What to do? I’ve tried all other plug-ins, but they are not what I’m looking for, this plug-in would be perfect :)

Mike

Hey Keir

Definitely some problems with the plugin and the rich text editor. It seems to disable saving – but on a slightly intermittent basis….

cheers

Mike

Leave a Comment

Ads Powered by Fusion

About Me

I am a web developer based in Bath in the UK with a focus on WordPress, PHP and JavaScript. I am also the co-founder of Viewport Industries - hosts of "Insites: The Tour" and publisher of the upcoming book "Insites: The Book". I help edit Smashing Coding and am a fan of fine coffee, cocktails, F1 and slow media.

Blog Categories

Projects