我应该在哪里放置短码文件? (WordPress)
我正在制作自定义插件,并试图这次制作短码。因此,我的插件文件夹中有三个文件。
- functions.php
- data.php
- shortcodes.php
,您可以猜到,add_shortCode和do_shortCode函数在shortcodes.php中。我正在关注本文 代码
include('custom-shortcodes.php');
主题函数的 .php。但是,我的短代码文件放在插件的内部,因此我将此代码放入
<?php
include (ABSPATH . '/wp-content/plugins/my-plugin/shortcodes.php');
?>
function.php中的主题文件夹中以包含我的文件,但请继续错误。我无法保存我的帖子。
我是在做正确的方式还是将其放在错误的文件中?
I'm making a custom plugin and trying to make a shortcode this time. So I have three files in my plugin folder.
- functions.php
- data.php
- shortcodes.php
And as you can guess, add_shortcode and do_shortcode functions are inside of shortcodes.php. I'm following this article and it said to put this code
include('custom-shortcodes.php');
inside of theme's functions.php. However, My shortcode file is placed inside of my plugin so I put this code
<?php
include (ABSPATH . '/wp-content/plugins/my-plugin/shortcodes.php');
?>
inside of functions.php in themes folder to include my file but keep getting me error. I cannot save my post.
Am I doing the right way or am I putting it in a wrong file with wrong code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您
.../wp-content/plugins/my-plugin
目录中有四个.php文件,通常命名为...然后您将您放入
my-plugin.php
文件代码中:这是此
require_once(plugin_dir_path(__file_____file_______file_______file_______file______file__ )。
加载源文件的代码行。__ file __ file __ file __
目前运行的PHP文件。
。'functions.php'
)附加到其中,然后还有很多其他内容需要介入
my-plugin.php
文件,您可以阅读有关在这里。开发插件时,不应编辑主题中的任何文件以加载它。 WordPress一旦激活插件就可以做到这一点。您将快捷代码放入您的帖子或页面以使用它。
您向我们展示的文章使用简编函数,但主题编辑是错误的。
Let's say you have four .php files in your
.../wp-content/plugins/my-plugin
directory, named typically ...Then you put into your
my-plugin.php
file code like this:It's this
require_once( plugin_dir_path( __FILE__ ) . 'functions.php' );
line of code that loads your source file.__FILE__
contains the pathname of the presently running php file.. 'functions.php'
) to that, andThere's a bunch of other stuff that needs to go into that
my-plugin.php
file, which you can read about here.When you develop a plugin, you should not edit any file in your theme to load it. WordPress does that once you have activated your plugin. You put the shortcode into your post or page to use it.
The article you showed us is accurate on how to create and use a shortcode function, but it's wrong about theme editing.