Trying to learn WP plugin development.

Followed all the instructions.

plugins/e4-test-1 directory.

Main php file (e4-test-1.php):

 * Plugin Name: Test 1
 * Plugin URI: http://xxxxx.xxx
 * Description: xxxxxxxxxxxxxxxxxx
 * Version: 1.0.0
 * Author: xxxxxxx
 * Author URI: http://xxxxxx.xxx
 * License: GPL2

My one an only php file with code (testhook.php):


function testhook() {
add_action( "wp_head", "testhook" );

It simply does nothing. View Source doesnot contain the string anywhere.

Of course I have activated the plugin, cleared caches e.t.c

Obviously my noobness stops me from finding the mistake


You need to call your custom file into your main plugin file. Without doing that, your custom file will not get called. Think of your main plugin file as your themes functions.php file and your custom file like a custom file that also holds functions

By default, Wordpress will only read your functions.php, and not your custom functions file. For wordpress to know to load that functions inside the custom file, you need to tell wordpress that there is a custom file with functions it should load. Normally, in a theme, you would use include or require_once. Here we would do the same, except, your path will differ from themes

So you can try the following in your main plugin file

require_once(dirname(__FILE__) . '/testhook.php');

Try to activate the debug mode in config.php: Set this to true:define('WP_DEBUG', false);

Deactivate any plugin you have running to make sure there isn't a Jquery error.

Now run it again. Maybe you should also start with something simpeler. The tag <script> wants to run something. Maybe your browser doesn't allow it (for what kind of reason)

Try following:

function testhook() {
add_action( "wp_head", "testhook" );
  • I already replaced with echo..Will try debug...where to put it? in the php file of the plugin? – e4rthdog Feb 5 '15 at 13:49
  • in your config.php file at the bottom is the following line:define('WP_DEBUG', false);. Change the false part to true. Where do you call this function? – Interactive Feb 5 '15 at 13:54
  • Added, also added debug bar plugin and everything is clear.The code is in proper php file inside the plugin directory – e4rthdog Feb 5 '15 at 13:57
  • updated my answer to include file names – e4rthdog Feb 5 '15 at 13:58
  • Oke this might be the dumbest solution I can offer you but did you activate your plugin? I just added a new plugin with your code and it works with me. Here is the complete code I used: <?php /* Plugin Name: test Description: description Author: name Version: 1.0 Author URI: http://www.example.com */ function testhook() { echo 'SOULISSSSSSSSSSSS'; } add_action( "wp_head", "testhook" ); ?> – Interactive Feb 5 '15 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.