我需要包括插件在我的WordPress主题没有插件激活。我有这样的台词:
include_once dirname( __FILE__ ) . '/math/class-constrained-array-rounding.php';
include( plugin_dir_path( __FILE__ ) . 'class.jetpack-user-agent.php');和
wp_enqueue_script( 'tiled-gallery', plugins_url( 'tiled-gallery/tiled-gallery.js', __FILE__ ), array( 'jquery' ) );
wp_enqueue_style( 'tiled-gallery', plugins_url( 'tiled-gallery/tiled-gallery.css', __FILE__ ), array(), '2012-09-21' );我认为我需要使用函数get_template_directory_uri()而不是plugin_dir_path来包含这些文件,但我很困惑。
我是WordPress的新手。有人能提出解决这个问题的办法吗?
发布于 2014-09-05 06:16:35
WP_PLUGIN_DIR.'/pluginName/'将为您提供到插件目录的绝对路径。
评论后的
插件是插件,主题文件是主题文件。别把这两者搞混了。您不能在主题目录中复制插件--因为东西不是那样工作的。
经过仔细的编辑,您可以将插件作为主题选项的一部分。
themes/mytheme/include/plugins/hello.php。require_once hello.php文件如下:定义(‘TEMPLATEPATH’,TEMPLATEPATH)。‘/include/’);定义(‘mytheme’,get_template_directory_uri()。‘/ require_once /’);mytheme_inc_path。‘'plugins/hello.php';a.如果我有一个更复杂的“插件”,那么代码将如下所示: require_once mytheme_inc_path。‘'plugins/myplugin/myplugin.php';//因为插件应该在myplugin.php中拥有自己的目录,所以您将对所需的脚本和样式进行排队,例如:函数mytheme_plugin_scripts() {wp_enqueue_script(’tiled-wp_enqueue_script‘,mytheme_inc_url )。“平铺画廊/平铺画廊”,数组(Jquery );wp_enqueue_style(“平铺画廊”,mytheme_inc_url )。“平铺-画廊/平铺-画廊”,数组(),‘2012-09-21’;}add_action(‘wp_enqueue_script’,'mytheme_plugin_scripts');hooks (筛选器、激活/失活或其他)。actions,但真正需要的除外如果您在脚本/样式队列中做了一些研究,您就会知道插件(存储在wp-content/plugins或wp-content/mu-plugins中的插件)使用了一些不同的函数来检索绝对/相对路径和uri。就像这样:
函数引用/wp队列脚本
https://wordpress.stackexchange.com/questions/160255
复制相似问题