Changing Default Attributes

This tutorial is for the Arconix Shortcodes plugin for WordPress

Many shortcodes in the Arconix Shortcodes plugin have options which allow you to alter how the shortcode looks or functions, whether it be to change the default size, color, style, etc…

For example, the default button is medium sized and white in color. If I wanted to make a big blue button, I’d enter the following shortcode (minus the * at the front)

[*button color=”blue” size=”large” url=”#”]Big Blue Button[/button]

That’s all well and good, but if you wanted every button you added to your site to be big and blue, typing all that out every time would become a hassle. What if you could just type

[*button url=”#”]Button[/button]

and get a big blue button? We can via a WordPress filter. You don’t need to know all the gory details of how filters work, just know that a filter allows us in this case to modify the default attributes that are passed to the various shortcodes.

You will need access to your theme’s functions.php file, which should be located at the root of your theme folder, to make use of these filters. Just add your code at the bottom of your functions.php file, before the closing ?>, if it’s there.

In order to make our default button big and blue, we simply have to alter the default size and color.

// Big Blue default button
add_filter( 'arconix_button_shortcode_args','my_button_defaults' );
function my_button_defaults( $defaults ) {

$defaults['color'] = 'blue';
$defaults['size'] = 'large';

return $defaults;
}

The add_filter function tells WordPress we want to filter some information. The first section in the parenthesis is the filter we want to modify, and the 2nd is the name of the function we created that’ll define the new values. Inside the my_button_defaults function, we tell WordPress to find the ‘color’ default and change it to ‘blue’ and the ‘size’ default and change it to ‘large’. You can make modifications like this for any shortcodes that have options. To find out the available options and the name of the filter you need to access, find the individual shortcode on the plugin’s wiki page.

Remember, this code will only change the shortcode’s default values. For example, small red buttons can still be created by using size=”small” and color=”red” in the button shortcode as normal

So that’s it — a little php shortens up those shortcodes and can save you a lot of time using them on your site.