Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I save widget code for wordpress?

I've googled around quite a lot, but can't seem to find where I should be saving the code for the widget I've created. It's a bit baffling.

So, can anyone tell me where I should save my widget?

Thanks, John.

like image 906
John Hunt Avatar asked Apr 27 '11 02:04

John Hunt


1 Answers

You need to put your widget code in either the functions.php file of your current theme, or within a plugin. In order to put it in a plugin, create a new folder in the plugins folder and create a .php file with the name of the folder you created within that folder. In that file, use this code to start your plugin:

<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
?>

Obviously, change the values to something useful for your plugin. You can then paste your widget code into this file and it should be ready to use.

Sources:

http://codex.wordpress.org/Writing_a_Plugin

http://codex.wordpress.org/Plugin_API

like image 75
tollmanz Avatar answered Sep 28 '22 09:09

tollmanz