3 回答

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
如果您使用相同的 css 類名,則在 css 文件中只需在要強(qiáng)制使用的屬性的分號(hào)之前添加 !important 即可。

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊
很難說如何在不查看主題源代碼的情況下使腳本出隊(duì)。無論如何,通常你只需要等到主題完成它的工作,掛接到 wp 并刪除搜索其句柄名稱的樣式。像這樣的東西:
add_action('after_setup_theme','alter_styles');
function alter_styles(){
wp_dequeue_style();
wp_dequeue_script();
}
相反,談到您的代碼,第一個(gè)問題是:您確定您在正確的時(shí)間、正確的位置加載了該代碼,還是它根本就被執(zhí)行了?你可以這樣做:
add_action('template_redirect','my_template_redirect');
function my_template_redirect(){
if (is_page('your_page')){
// Load class / do stuff with scripts/styles
}
}
確保僅針對該特定頁面執(zhí)行代碼

TA貢獻(xiàn)1807條經(jīng)驗(yàn) 獲得超9個(gè)贊
有多種方法可以讓您的樣式表在加載其他樣式表后加載。您已經(jīng)嘗試了幾種方法,但是父主題的優(yōu)先級非常高9999,因此您需要使用更高的主題,否則它將無法工作。
1. 優(yōu)先權(quán)
9999您在 中使用優(yōu)先級add_action,但是如果您查看父主題,它會(huì)使用:
add_action( 'wp_enqueue_scripts', array( 'OCEANWP_Theme_Class', 'custom_style_css' ), 9999 );
您的代碼的優(yōu)先級實(shí)際上并不高于父主題,因此您需要再次提高,例如
add_action('wp_enqueue_scripts', array($this, 'cmmc_styles'), 10000);
2.出隊(duì)(注意,需要匹配入隊(duì)時(shí)使用的值)
您說出列對您不起作用,但請注意,當(dāng)您使樣式出列時(shí),優(yōu)先級決定了它何時(shí)運(yùn)行 - 就像您入隊(duì)時(shí)一樣 - 因此您需要使用比入隊(duì)時(shí)使用的優(yōu)先級更高的優(yōu)先級。它還必須使用相同的鉤子(或更高版本的鉤子)。
正如我們在上面看到的,您需要以高于9999它們排隊(duì)的優(yōu)先級來執(zhí)行此操作,例如
function dequeue_oceanwp_styles() {
wp_dequeue_style('oceanwp-style');
wp_deregister_style('oceanwp-style');
}
/* Now call this function with a higher priority than 9999 */
add_action( 'wp_enqueue_scripts', 'dequeue_oceanwp_styles', 10000);
3. 依賴關(guān)系
如果這不起作用,您可以在樣式之間設(shè)置依賴關(guān)系以強(qiáng)制執(zhí)行順序。
當(dāng)您使用wp_register_style或 時(shí)wp_enqueue_style,您可以指定您正在注冊/排隊(duì)的樣式表的依賴關(guān)系 - 即您的樣式表所需的其他樣式表。這意味著您正在注冊的樣式表只有在它所依賴的樣式表之后才會(huì)加載。
為此,您需要傳遞必須首先加載的樣式表的句柄數(shù)組,例如
// create an array with the handles of the stylesheets you want to load before yours
$dependencies = array('oceanwp-style', 'oceanwp-hamburgers', /* etc. */ );
/* Noew pass this in as the dependencies for your stylesheets */
wp_register_style('bootstrap_css',
'https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css',
$dependencies, /* array of dependencies */
NULL, 'all' );
wp_enqueue_style('bootstrap_css');
/* Add bootstrap to the dependencies, if your custom_styles needs it */
$dependencies[] = 'bootstrap_css';
wp_enqueue_style('custom_styles',
plugins_url('/assets/css/styles.css', __FILE__),
$dependencies, /* array of dependencies */
);
- 3 回答
- 0 關(guān)注
- 146 瀏覽
添加回答
舉報(bào)