我正在修改现有的 WP 插件,方法是制作一个单独的插件来扩展它。我想编写将覆盖插件的 CSS。但是,当我尝试将样式表排入队列时,它不起作用。我知道它不起作用,因为我在中添加了一个简单的表单includes()
并尝试将单词设置为红色以查看更改。为什么这不起作用?
注意 - 我正在使用plugins_loaded
我在 codex 中读到的 action hook 之前发生过wp_enqueue_script
。所以我不怀疑我的排队错过了时机,但我是 WP dev 的新手,如果我错了,请纠正我。
更新- 请在下面查看我更新的 CSS 代码。#id 选择器本身并没有将文本着色为红色,但是当我添加 p (段落选择器)时它起作用了。这两个选择器都不能单独工作,只有在我同时添加两者时才有效。为什么是这样?
查找-do-for-anspress.php
if (! defined('WPINC')) {
die;
}
Class Find_Do_For_Anspress {
/**
* Class instance
* @var object
* @since 1.0
*/
private static $instance;
/**
* Get active object instance
*
* @since 1.0
*
* @access public
* @static
* @return object
*/
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new Find_Do_For_Anspress(); }
return self::$instance;
}
/**
* Initialize the class
* @since 2.0
*/
public function __construct() {
if ( ! class_exists( 'AnsPress' ) ) {
return; // AnsPress not installed.
}
if ( ! defined( 'FIND_DO_FOR_ANSPRESS_DIR' ) ) {
define( 'FIND_DO_FOR_ANSPRESS_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'FIND_DO_FOR_ANSPRESS_URL' ) ) {
define( 'FIND_DO_FOR_ANSPRESS_URL', plugin_dir_path( __FILE__ ) );
}
$this->includes();
add_action( 'wp_enqueue_scripts', array($this, 'fd_enqueue'));
}
private function includes() {
require_once (FIND_DO_FOR_ANSPRESS_DIR.'braintree/lib/braintree.php');
require_once (FIND_DO_FOR_ANSPRESS_DIR.'fd-braintree/fd-bt-keys.php');
require_once (FIND_DO_FOR_ANSPRESS_DIR.'fd-braintree/fd-process-trans.php');
require_once (FIND_DO_FOR_ANSPRESS_DIR.'fd-braintree/fd-bt-functions.php');
require_once (FIND_DO_FOR_ANSPRESS_DIR.'fd-braintree/fd-bt-form.php');
require_once (FIND_DO_FOR_ANSPRESS_DIR.'includes/fd-ask-form.php');
}
public function fd_enqueue() {
wp_enqueue_style( 'fd_for_anspress_css', FIND_DO_FOR_ANSPRESS_DIR.'css/fd-css.css', array(jquery), null); //handle, source, dependencies, version, media (the type of media for which the stylesheet is designed, e.g. mobile, web, print...)
//wp_enqueue_script( 'fd_for_anspress_js', FIND_DO_FOR_ANSPRESS_DIR.'fd-braintree/js/fd-braintree-js.js', array(), null); used require_once to directly add it to fd-bt-form.php
}
} //End class
function find_do_for_anspress() {
$FDClassStart = new Find_Do_For_AnsPress();
}
add_action( 'plugins_loaded', 'find_do_for_anspress' );
//HTML "testing" block
echo '<p id="checkout">Testing the enqueued CSS</p>';
fd-css.css 尝试 1
<style>
#checkout {
color: red;
}
</style>
fd-css.css 尝试 2
<style>
#checkout {
color: red;
}
p {
color: red;
}
</style>