curiouswebster
asked on
WordPress "Hello World!" plug-in adds itself to all new pages?
I created my first PHP WordPress plugin and find that it ads itself to any new page, but I want to be able to add it when I want to.
I was not sure how much of a header, or any header, may be required by WP to be considered a plug-in.
I zipped it up, along with an empty index.html file, then zipped it into hello.zip. I added the plugin using the WP Admin panel, and found it worked.
BUT, any new page gets "Hello World!"
How do I prevent it from going into every page? And how do I place the plug-in on a page, where I would like it to appear?
I was not sure how much of a header, or any header, may be required by WP to be considered a plug-in.
I zipped it up, along with an empty index.html file, then zipped it into hello.zip. I added the plugin using the WP Admin panel, and found it worked.
BUT, any new page gets "Hello World!"
How do I prevent it from going into every page? And how do I place the plug-in on a page, where I would like it to appear?
<?php
/**
* Hello World! for WordPress
*
* @package hello
* @link https://patriotssoar.com
* @author My name
* @copyright 2021 My name
* *
* Plugin Name: hello
* Description: A test WordPress plugin.
* Version: 1.0
* Plugin URI: https://mydomain.com
* Author: My name
* Author URI: https://mydomain.com
* Text Domain: hello
* Domain Path: /languages/
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
echo "Hello World!";
?>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
It's worth mentioning that a more flexible way of using a plugin to add content to a page is by defining a new shortcode that you can add to your page, or perhaps by defining a Gutenberg block that can be selected by the user. Hard-coding which page content displays on is very limiting.
ASKER
I would like to hear more about that idea of defining a Gutenberg block that can be selected by the user. Does the "user" mean the developer? Or the actual user?