Avatar of curiouswebster
curiouswebsterFlag for United States of America

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?


 <?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!";
?>

Open in new window

Web DevelopmentPHPWeb Languages and StandardsWordPressWeb Development Software

Avatar of undefined
Last Comment
curiouswebster
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

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.
Avatar of curiouswebster

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?


PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo