How To Make A Simple Konami Code Plugin

Tutorials | By | 31 January 2011 | Comments 0

Konami codes have been used since the mid eighties are are present in a huge number of video games particularly within that era, Konami codes basically allowed gamers to gain extra lives and such by entering the code.

Website owners on Shopify can choose to do the web development themselves a plugin or hire an expert.

For those of use that don’t know the Konami code here it is: Up, Up, Down, Down, Left, Right, Left, Right, B, A, Start (in this tutorial Start is replaced with ENTER)

So here is a simple plugin which adds a Konami code to your WordPress install, we are using the awesome .js from SnapTortoise

Lets get started! Open a new document in your favorite text editor and add the following:

<?php
/*
Plugin Name: EZ Konami Code
Plugin URI: http://wpzine.com
Description: Plugin which adds a Konami code to your WP install.
Author: Paul Maloney
Version: 1.1
Author URI: http://paulmaloney.net
*/


function ezkonami() {

// this adds the Konami code
echo '<script type="text/javascript" src="http://konami-js.googlecode.com/svn/trunk/konami.js"></script>
<script type="text/javascript">
konami = new Konami()
konami.code = function() {
alert("AWESOME!! You entered the hidden Konami code!")
}
konami.load()
</script>';
}
 

add_action('wp_footer', 'ezkonami');

?>

You can then save the file with a .php extension, eg: ezkonami.php, then upload to your blog’s plugin directory and enable in your admin section.

You can then visit your blog and test it out!

OK that’s the plugin built, but what does all the code actually do? Lets break it down:

/*
Plugin Name: EZ Konami Code
Plugin URI: http://wpzine.com
Description: Plugin which adds a Konami code to your WP install.
Author: Paul Maloney
Version: 1.1
Author URI: http://paulmaloney.net
*/

This section tells your blog that this is a plugin, and identifies it by name so you can select it in your plugin section of your admin panel.

function ezkonami() {
// this adds the Konami code
echo '<script type="text/javascript" src="http://konami-js.googlecode.com/svn/trunk/konami.js"></script>
<script type="text/javascript">
konami = new Konami()
konami.code = function() {
alert("AWESOME!! You entered the hidden Konami code!")
}
konami.load()
</script>';
}

This is the main function, this tells the blog to show the javascript and the alert message, you can see we are calling the .js file directly from googlecode which keeps it nice and quick.

alert("AWESOME!! You entered the hidden Konami code!")

This simple plugin shows an alert box when the Konami code is entered, you can customize this by altering the alert message as shown in this section.

add_action('wp_footer', 'ezkonami');

The final part tells the plugin to load the .js in the blogs footer which are a common best practice as it keeps your blogs loading time that bit quicker.

Conclusion

This will only take a few minutes and whilst not an important plugin by any means but it might just raise a smile amongst your readers.

Paul Maloney is a UK based web designer/developer and runs the design agency Tropica. He particularly enjoys using and working with WordPress and has a keen interest in typography. You can also follow Paul on Twitter.

Visit Paul Maloney's website

Be The First To Comment

Leave A Comment.