WORDPRESS插件开发学习(一)HELLO WORLD,wordpresshello
WORDPRESS插件开发学习(一)HELLO WORLD,wordpresshello
WORDPRESS插件开发学习系列文章第一篇,在每篇文章的后面追加固定的字符“Hello World”
一.打开wordpress目录->wp-content->plugins
二.在plugins下新建一个目录1100w-hello-world
三.在1100w-hello-world下新建两个文件
1100w-hello-world.php 插件所必须文件,插件的入口文件。放置插件主要功能代码。如果插件包含功能比较多,可以将功能代码放置到不同的php页面中,在本例中,因为只显示hello world,所以功能代码脂肪到1100w-hello-world.php代码中
readme.txt 如果需要将插件分享到wordpress社区中,需要使用这个文件。测试时,可是建立不使用。
建立完成后,目录结构如下:
四.编辑1100w-hello-word.php文件,先输入如下代码
<?<span>php </span><span>/*</span><span> Plugin Name: Hello-World Plugin URI: http://1100w.com/ Description: 最简单的插件实现,在每篇文章的后面追加hello world Version: 1.0 Author: 1100w Author URI: http://1100w.com License: GPL </span><span>*/</span> ?>
代码保存后,打开wordpress,进入后台插件管理,虽然没有加入功能代码,但可以看到我们开发的插件信息
以上的注释代码便是wordpress插件的描述代码,格式固定,每个wordpress插件所必须遵守的。分别对应于:
插件名
插件的官方链接
插件描述
版本
作者
作者的官方链接
开源协议
五.在1100w-hello-word.php加入功能代码
<span>//</span><span>添加过滤器,在the_content显示时,执行hello_world函数,追加返回数据</span> add_filter('the_content','hello_world'<span>); </span><span>//</span><span>回调函数</span> <span>function</span> hello_world(<span>$content</span><span>) { </span><span>//</span><span>检测是否为single页面.</span> <span>if</span><span> ( is_single() ) { </span><span>//</span><span>添加Hello World.</span> <span>return</span> <span>$content</span> . "<h1 id="Hello-World"> Hello World </h1>"<span>; } </span><span>else</span><span> { </span><span>//</span><span>如果是其它页面不予处理。</span> <span>return</span> <span>$content</span><span>; } }</span>
六.激活插件,打开一篇链接,插件功能显示如下:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use WordPress plug-ins to achieve instant query function WordPress is a powerful blog and website building platform. Using WordPress plug-ins can further expand the functions of the website. In many cases, users need to perform real-time queries to obtain the latest data. Next, we will introduce how to use WordPress plug-ins to implement instant query functions and provide some code samples for reference. First, we need to choose a suitable WordPress plug-in to achieve instant query

How to use WordPress plug-in to implement email subscription function In today’s Internet age, email subscription function has become an indispensable part of website operation. Through the email subscription function, we can push the latest news, activities, offers and other information to users in a timely manner to enhance user stickiness and interactivity. In the WordPress website, we can implement the email subscription function by using plug-ins. The following will introduce how to use the WordPress plug-in to implement the email subscription function. Step 1: Choose the right plugin

How to Develop an Auto-Updating WordPress Plugin WordPress is a very popular open source content management system (CMS) with a rich plugin market to extend its functionality. To ensure that plugins are always up to date and secure, developers need to implement automatic updates. In this article, we’ll walk you through how to develop an auto-updating WordPress plugin and provide code examples to help you get started quickly. Preparation Before starting development, you need to prepare the following key steps: Create

How to Add Online Payment Function to WordPress Plugin With the rapid development of the e-commerce industry, adding online payment function to the website has become a critical need. For those who use WordPress as a website development platform, there are many ready-made plugins that can help them achieve this goal. This article will introduce how to add online payment functionality to WordPress plug-in and provide code samples for reference. Determine the payment interface Before adding the online payment function, you must first determine the payment interface to use. current city

How to Use WordPress Plugins to Implement Instant Question Function WordPress is a powerful and popular blogging and website building tool. It provides many plug-ins that allow bloggers to customize and enhance the functionality of their blog according to their needs. One of the very useful features is Live Questions, which allows bloggers to interact with readers in real time and answer their questions. This article will introduce how to use a WordPress plug-in to implement the instant question function and provide code examples. Step 1: Install the Plugin First, in WordP

How to deal with error messages when WordPress plug-in installation fails? As one of the most popular content management systems currently, WordPress has a rich plug-in library, providing users with various functional extensions and customization options. However, when using WordPress, sometimes plug-in installation fails, and error messages may appear, making users feel confused and anxious. This article will introduce some common WordPress plug-in installation failure error messages and how to deal with these problems. 1. Report

How to develop a WordPress plug-in that automatically generates project progress. In the process of project management, it is very important to understand the project progress. For users who use WordPress to build websites, being able to directly view project progress in the WordPress backend will greatly improve work efficiency. Therefore, it is very beneficial to develop a WordPress plugin that automatically generates project progress. This article describes how to develop such a plug-in and provides code examples. Plugin Overview The main functions of this plugin are

How to develop a WordPress plug-in that automatically generates e-books. With the popularity of social media and e-readers, e-books have become one of the important ways for people to obtain and share knowledge. As a WordPress developer, you may be faced with the need to create and publish e-books. To simplify this process, we can develop a WordPress plugin that automatically generates e-books. This article will teach you how to develop such a plug-in and provide code examples for reference. Step 1: Create the basic file structure of the plugin first
