shortcodes posts

WordPress code plugin, a quick solution

I’m slowly copying the markdown versions of my posts after my recent move of this blog. It really is tedious, and I don’t think I’ll finish anytime soon, so in the meantime I created a plugin to output the [ code] shortcode that put in my post export in the same way that markdown does. This is the first plugin and shortcode I’ve created in a long while, but it was relatively quick to do working off of my posts on plugins and shortcodes. The biggest time consumer was figuring out how to deal with whitespace issues. Apparently, WordPress sometimes will add <p> and <br /> to shortcode content. Also, there were leading and trailing line breaks adding unnecessary space. My quick solution:

Continue reading post "WordPress code plugin, a quick solution"

WordPress: Shortcodes

I’ve been playing with shortcodes in WordPress. They provide a nice way to allow the client to insert certain content without them needing to even deal with HTML, such as predefined pieces or wrappers with specific classes or structure. They are the only way to effectively run PHP functions from within a page without actually allowing PHP code to be run. This can allow pulling things from data, such as custom fields or from Pods CMS. The built in shortcode, for instance, pulls image data from the database about images connected to a post.

It’s very easy to add a shortcode. You create a function that does what you want and returns a string to output in place of the shortcode then use the add_shortcode() function of WordPress to attach it as a shortcode. The function is done like:

function repFunctionName($repArguments, $repContent=null){
    return "some string";

$repArgument is an array of arguments passed to the shortcode like:

[repShortcode repArgument1="value1" repArgument2="value2"]
Continue reading post "WordPress: Shortcodes"