破坏 WordPress 网站的短代码
我正在我的本地版本的 WordPress 网站上为 WordPress 创建新的短代码。
在functions.php中,我添加了例如:
function shortTest() {
return 'Test for shortcodes ';
}
add_shortcode('shortTestHTML', 'shortTest');
仅添加函数就可以了,但是当我添加add_shortcode()部分时,我遇到了一个主要问题。
它以某种方式破坏了某些东西,我收到 500 个错误,这意味着我什至无法再在本地加载我的网站。
有什么想法吗???
非常感谢!
编辑:
来自 PHP 错误日志: [21-Jun-2011 19:02:37] PHP 致命错误:在第 4505 行 /Users/jonas/Sites/jll/wp-includes/functions.php 中调用未定义函数 add_shortcode()
I am creating new shortcodes for Wordpress on my local version of a Wordpress website.
In functions.php, I am adding for example:
function shortTest() {
return 'Test for shortcodes ';
}
add_shortcode('shortTestHTML', 'shortTest');
Adding the function only is OK, but when I add the add_shortcode() portion, I get a major issue.
It breaks something somehow and I get 500 errors, meaning I can't even load my website locally anymore.
Any thoughts???
Thanks so much!
EDIT:
From PHP Error Log:
[21-Jun-2011 19:02:37] PHP Fatal error: Call to undefined function add_shortcode() in /Users/jonas/Sites/jll/wp-includes/functions.php on line 4505
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
1) 确保您已在某处包含
shortcodes.php
文件(例如,在wp-load.php
或任何其他更合适的位置)。2)确保您的安装中确实存在此文件(我认为您有,否则我们会看到不同的错误)。
3)你从哪里调用这个函数(我看到它是从
functions.php
调用的,但是在哪里)?这里可能存在的问题 -functions.php
在shortcodes.php
之前加载,并且如果您在shortcodes 之前使用该
加载后您很可能会看到此错误。仔细检查该位置的代码 - 也许将对add_shortcode
函数.phpadd_shortcode
的调用移至另一个位置。1) Make sure that you have included
shortcodes.php
file somewhere (for example, inwp-load.php
or whatever other more appropriate place may be).2) Make sure that this file does exist on your installation (which I think you have otherwise we would see a different error).
3) Where do you call this function from (I see it is called from
functions.php
, but which place)? Possible problem here --functions.php
is loaded prior toshortcodes.php
, and if you do use thatadd_shortcode
function beforeshortcodes.php
is loaded you most likely will see this error. Double check your code in that place -- maybe move the call toadd_shortcode
to another place.提到的
functions.php
不在wp-include/目录
中。它位于:
wp-content/themes//functions.php
mentioned
functions.php
is not inwp-include/ directory
.it is in:
wp-content/themes/<your-theme-name>/functions.php
你说在functions.php中添加这个?好吧,我不知道这一点,我的方法是在 wp-content/plugins 文件夹中创建一个文件夹,例如 Shortcodetest。
在此文件夹中创建一个
shortcodetest.php
文件。在该文件中,您基本上编写了代码:
?>
然后你以管理员身份登录,你会看到一个插件ShortCodeTest,激活它。然后您可以在帖子中使用短代码。
请注意,注释很重要......它们显示在插件描述中。
adding this in functions.php you say? Well I don't know about that, the way I did it was create a folder inside the wp-content/plugins folder, e.g. shortcodetest.
Inside this folder create a
shortcodetest.php
file.in that file you basically write your code:
?>
Then you login as admin, you will see a plugin ShortCodeTest, activate it. Then you can use the shortcode in your posts.
Note that the comments are important... they show up in the plugin description.
我有一种方法来执行它们,但有点复杂:)
您需要通过将短代码(例如:[inline ....])放在
then这是放置在 function.php 末尾的函数。
然后,您可以调用函数 parse_execute_and_echo_shortcode 并为其提供包含短代码的文件的路径。
希望可以帮助某人
I got a way to execute them but it's a little triky :)
You need to change a little bit your template by putting your shortcode (for example: [inline ....]) between
<shortcode></shortcode>
thenHere is the function to place at the end of your function.php.
Then you can call
function parse_execute_and_echo_shortcode
and giving it the path to your file containing the shortcodes.Hope that can help someone
检查您的 error.log 文件(它应该位于您的 apache 日志文件夹中)。
这可能与 add_shortcode 不作为函数存在有关。
Check your error.log file (it should be in your apache log folder).
It probably has to do with add_shortcode not existing as a function.
将您的短代码放入文件
/wp-includes/shortcodes.php
中,这样您就可以确保在所有吹哨声启动并运行时加载它。Put your shortcode in the file
/wp-includes/shortcodes.php
this way you make sure it will be loaded when all the blows and whistles are up and running.