当前位置:网站首页>一步一步教你制作的第一个 WordPress 插件
一步一步教你制作的第一个 WordPress 插件
2022-06-28 16:10:00 【华为云】
WordPress 中的插件是添加或扩展功能的组件,可根据需要启用或禁用,并且不会干扰核心程序/软件及其代码。WordPress 被设计为轻量级和流畅的,以增加灵活性并减少对基本网站功能可能不重要的代码。然后插件添加自定义特性和功能,允许用户根据他们的特定要求设计站点。
在本指南中,将学习如何开发的第一个 WordPress 插件。
先决条件:
- WordPress 安装
- PHP 基础知识
制作插件的步骤——
1.转到 WordPress 安装 -> WordPress/wp-content/plugins

2.在此处创建一个新文件夹并将其命名为“插件名称”,在本例中为 First-Plugin

3.接下来,在此文件夹中创建一个新的 PHP 文件,并将其命名为与本例中的文件夹相同的名称 First-Plugin.php

4.现在,我们添加插件的名称。添加包含在文件中的 PHP 注释中的插件名称。
PHP 文件 First-Plugin.php 的代码 –
<?php/*** Plugin Name: First Plugin**/?>
5.现在,转到 WordPress Dashboard->Plugins,在这里可以看到我们新创建的插件及其名称。

6.我们不应该将描述留空,因为它可以帮助用户了解插件的用途。所以让我们通过在“Plugin Name:”之后添加一个新的注释行来添加我们插件的描述,标题为“Description”并保存它。PHP 文件 First-Plugin.php 的代码 –
<?php/*** Plugin Name: First Plugin* Description: This is my first Plugin.**/?>
7.我们成功添加了我们插件的描述现在转到 Dashboard->plugin 看看它的样子。

8.接下来,我们为我们的第一个插件添加一些功能。我们将添加一个名为 first_plugin() 的基本函数,它会打印“HELLO This is my first Plugin”。及其短代码允许将其放置在 WordPress 帖子或页面上。
代码 -
<?php/*** Plugin Name: First Plugin* Description: This is my first Plugin.**/function First_Plugin(){ $content="HELLO This is my first Plugin."; return $content;}add_shortcode('myplugin', 'First_Plugin')?>
9.为了显示这个函数的输出值,我们使用了 WordPress 的简码特性。转到帖子->编辑或创建新帖子。在那里添加我们刚刚制作的插件的简码。
简码 - [myplugin]

10.要查看插件输出,请浏览网站并打开我们添加插件短代码的帖子。
这是它的样子 -

11.现在,要多次使用此插件功能,我们可以多次使用此短代码。只需在我们需要此输出的任何地方添加简码。

12.检查帖子以获取更新的输出,我们得到两个相同的句子,因为我们在这篇帖子中使用了两次短代码。

现在我们有了我们的插件,它返回一个值,可以通过使用简码在任何我们想要的地方使用它。
边栏推荐
- 【Hot100】2.两数相加
- 【杂谈】2021/01/31 哦豁
- 首次失败后,爱美客第二次冲刺港交所上市,财务负责人变动频繁
- 访中国信通院王蕴韬:数实融合赋能文化产业繁荣发展
- Code implementation of gain (4) -- gap dataset missing data filling based on GaN (sequence) [improved version]
- 【Hot100】1. Sum of two numbers
- PID控制详解[通俗易懂]
- Slim gain (sgain) introduction and code implementation -- missing data filling based on generated countermeasure network
- 24岁秃头程序员教你微服务交付下如何持续集成交付,学不会砍我
- 3. caller service call - dapr
猜你喜欢
![[MySQL] official website document learning query statement SQL precautions](/img/aa/bf27b609e2fda1edaa46f134fc5626.png)
[MySQL] official website document learning query statement SQL precautions

O & M - unified gateway is very necessary

平台即代码的未来是Kubernetes扩展

Visual studio 2019 software installation package and installation tutorial

知道这几个命令让你掌握Shell自带工具

Internet of things cloud convergence Security Guide

General solution of island problems and DFS framework

Etcd可视化工具:Kstone简介(一)

Geoffrey Hinton: my 50 years of in-depth study and Research on mental skills

What are the most powerful small and medium-sized companies in Beijing?
随机推荐
2019 CSP J2入门组 CSP-S2提高组 第2轮 视频与题解
昨日元宇宙|Meta “元宇宙”部门一季度亏损29.6亿美元,六福珠宝发行数字藏品
NOIP1998-2018年普及组 CSP-J2 2019 2020 解题报告及视频
REDIS00_ Explain redis Conf configuration file
【Hot100】2.两数相加
tablestore中可以使用sql查询可以查出表中所有的数据吗?
请问下大家有遇到过这种设置的主健和数据库一致的错误吗?
The world has embraced Web3.0 one after another, and many countries have clearly begun to seize the initiative
Why MySQL table connection is faster than subquery
Convolutional neural networks for machine learning -- an introduction to CNN
开源技术交流丨一站式全自动化运维管家ChengYing入门介绍
[golang] how to install iris
Design details of the full stack CRM development tool webclient UI workbench
如何查询数据库中一个表中的所有数据呢?
Slim gain (sgain) introduction and code implementation -- missing data filling based on generated countermeasure network
Cloud sports, 360 ° witnessing speed and passion
PID控制详解[通俗易懂]
逆向调试入门-PE结构详解02/07
[MySQL] official website document learning query statement SQL precautions
【Hot100】2. Add two numbers