
Hi,
So are you one of those people who like to have a easy life when it comes to ‘blogging? Well I’m sure half of the population likes it easy sometimes! Now I’m speaking in terms of making things a little bit more easy access when it comes down to using your custom functions or custom features within your WordPress blog.
Before I begin you can read more about shortcodes in WordPress here. (Definitely check it out!)
And shortcodes certainly do that for you in a way of making your own code boxes if you post tutorials on your blog or from just making notes for your readers to take on board when reading your article, all these things boost your blog and helps your visitors enjoy their visit to the site.
So anyway’s enough about it, by now you have gone on that link and liked the sound of it – well now I’m going to show you a simple way of doing this and remember when I mean simple I mean it. This script I’m about to show you can be enhanced in many ways you could possibly think of, I always say let your mind go wild with creations the possibilities are endless! Let’s begin…
#1 Basic Code…
function myshortcode( $atts, $content = null )
{
if(empty($content)) //Check to see if the content is empty or not...
{
echo 'I have no mood I\'m not human!';
}
else
{
echo 'My mood today is: <b>' . $content . '</b>';
}
}
}
add_shortcode('mood', 'myshortcode');
Once you’ve written the code above you will need to save this in your ‘functions.php’ file – if you don’t have a ‘functions.php’ file in you’re theme folder then just create one, it’s not a problem really!
Then just save the file – and then create an example post and use this:
[mood]Happy!!![/mood]
This will then display:
“My mood today is Happy!!!“
However, you could use this for many other purposes not just show what sort of mood you are in – that was just used as an example to show what can be done with just using custom shortcodes within your posts. The possibilities are just endless and I use this method myself on this website to create some easy accessed features for when I write these tutorials and of course when I do different pages, it comes in use for those things without a doubt – but don’t take my word for it go do it yourself and you’ll see what I mean!
Remember the script above make sure use <?php before anything and then ?> at the end of the script, this is important for PHP scripts as they will not even function without it…common sense? (only speaking truthfully!)
I hope you found this useful if you do be sure to subscribe to our feeds and follow us on Twitter @InsanelyTech!



