Jump to content

Help with my first super simple "Hello World" Wordpress plugin


Cp1
Go to solution Solved by cyberRobot,

Recommended Posts

I am trying to write my first plugin.

 

So I read some tutorials and figured I'd start with a simple plugin to make sure I understood everything I read. I just wanted to echo "Hello World" on the screen. Simple.

 

I created the plugin and saw it in my admin. I activated it. So far, so good. Then... nothing happens. My code is extremely simple. I'm sure someone will look at it and see the problem.

 

I did some more research online and I tried to echo the message several ways:

 

<?php

 

/*

Plugin Name: Hello

*/

 

function hello_world() {

echo "Hello!";

print("Hello World");

}

 

add_action('wp_print_scripts', 'hello_world');

 

add_action('get_header', 'hello_world');

 

add_action('get_footer', 'hello_world');

 

add_action('wp_header', 'hello_world');

 

add_action('wp_footer', 'hello_world');

 

?>

Link to comment
Share on other sites

Hmmm, interesting. I will check on that.

 

I will check the name. I will also check the cache settings on my MAMP server. I cleared my browser cache.

 

Did the message show up on the header and footer?

 

I appreciate the response!

Link to comment
Share on other sites

The code looks like it should work, but your hook choices are a bit off. I know you're just playing around and trying to learn, but the wp_print_scripts hook has been replaced with wp_enqueue_scripts, and the get_footer and get_header hooks aren't mean to be used for output as any output will happen before the markup.

 

While testing, you may be better off using the the_content hook to prepend or append any output to the WP post content. That way you can see it right there in the middle of the page.

Link to comment
Share on other sites

Great, thanks for the help! I had to adjust some settings.

 

 

Thanks for the advice about the wp_print_scripts and the get_footer and get_header. When my plugin didn't work I started throwing everything at the problem just to get my message to show up.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.