【发布时间】:2017-03-07 10:18:56
【问题描述】:
我在/wp-content/plugins 目录中创建了一个名为customshortcode 的文件夹。 add_shortcode command 应该将短代码与函数链接起来。
在/wp-content/plugins/customshorcode/我创建了2个文件:main.php和test.php
主要的php内容是:
<?php require_once('../../../wp-includes/shortcodes.php'); ?>
<?php function custom_shortcode_func() {
include_once('test.php');
}
add_shortcode('customshortcode','custom_shortcode_func');
?>
而test.php只是显示一个分割块:
<style>.testdiv{border:1px solid black; width:300px; heigh:300px;}</style>
<div class="testdiv"></div>
我首先运行/wp-content/plugins/customshorcode/main.php 文件以查看没有错误和简单的白屏。我认为应该保存短代码。
但是当我在页面中输入 [customshortcode] 时,我没有显示除法,而是显示文本 [customshortcode]。
我想我需要以某种方式将页面类型链接到插件或类似的东西。你能帮帮我吗?
【问题讨论】:
-
在页面中添加 [customshortcode] 的位置和方式?
-
在您的
test.php中写:return '<style>.testdiv{border:1px solid black; width:300px; heigh:300px;}</style><div class="testdiv"></div>';。以及为什么包含/wp-includes/shortcodes.php?? -
因为没有它,当我到达 main.php 并在 URL 栏中运行它时,我得到:致命错误:调用 C:\MAMP\htdocs\new\ 中的未定义函数 add_shortcode() wp-content\plugins\customshortcode\main.php 在第 8 行
-
也在 test.php 我需要打开和关闭 标签吗?目前我只有上面没有标签的return语句。
-
@SamuelJMathew 我只是创建了一个新页面,添加了一个标题,并将短代码放入内容中,点击预览页面