0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WordPressで親テーマの余計なCSSを削除

Last updated at Posted at 2020-12-08

ワードプレスのテーマtwentytwentyを基盤に、wp_head( )を記述した際にビューが崩れる問題に対し、wp_head( )内で親テーマのCSSを読み込まないようにする実装を行ったので、備忘録的にこの記事を残す。

環境情報

PHP:version 7.3.12
WordPress:version 5.5.3
WPテーマ:twentytwenty

作業

子テーマのfunction.phpに以下を記述することで解決しました。

function.php
//parent-style-cssの削除
function my_delete_plugin_files() {
    wp_dequeue_style('parent-style');
}
add_action( 'wp_enqueue_scripts', 'my_delete_plugin_files' );

// //twenty-twenty系cssの削除
function remove_enqueue_parent_style() {
    $name1 = 'twenty-twenty-style';
    $name2 = 'twenty-twenty-print-style';
    if( wp_style_is( $name1 ) ) { wp_dequeue_style( $name1 ); }
    if( wp_style_is( $name2 ) ) { wp_dequeue_style( $name2 ); }
}
add_action( 'wp_enqueue_scripts', 'remove_enqueue_parent_style', 11);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?