Cp1 Posted January 20, 2016 Share Posted January 20, 2016 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/300585-help-with-my-first-super-simple-hello-world-wordpress-plugin/ Share on other sites More sharing options...
Solution cyberRobot Posted January 20, 2016 Solution Share Posted January 20, 2016 For what it's worth, the plugin code worked for me. Have you tried changing the file/folder/plugin name? Perhaps the name you're using conflicts with another plugin, like Hello Dolly. Quote Link to comment https://forums.phpfreaks.com/topic/300585-help-with-my-first-super-simple-hello-world-wordpress-plugin/#findComment-1530147 Share on other sites More sharing options...
Cp1 Posted January 20, 2016 Author Share Posted January 20, 2016 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! Quote Link to comment https://forums.phpfreaks.com/topic/300585-help-with-my-first-super-simple-hello-world-wordpress-plugin/#findComment-1530151 Share on other sites More sharing options...
cyberRobot Posted January 21, 2016 Share Posted January 21, 2016 Did the message show up on the header and footer? Yep, the messages showed up in both places. Quote Link to comment https://forums.phpfreaks.com/topic/300585-help-with-my-first-super-simple-hello-world-wordpress-plugin/#findComment-1530184 Share on other sites More sharing options...
maxxd Posted January 21, 2016 Share Posted January 21, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/300585-help-with-my-first-super-simple-hello-world-wordpress-plugin/#findComment-1530189 Share on other sites More sharing options...
Cp1 Posted January 21, 2016 Author Share Posted January 21, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/300585-help-with-my-first-super-simple-hello-world-wordpress-plugin/#findComment-1530200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.