2017-02-15 8 views
0

私は子テーマを扱っていますが、WordPressがエディタインターフェイスにファイルを表示していても、親テーマのファイルを上書きしません。私はここでいくつかの答えを見てきましたが、誰も働いていません。私は多くの異なるバリエーションを試してみましたが、そのうちの単一のものが働いていないWordPressの子テーマが他のファイルを上書きしない

<?php 
require_once(get_stylesheet_directory_uri() . '/lib/custom.lib.php'); 
add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles'); 
function my_theme_enqueue_styles() { 
    wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css'); 

} 
?> 

<?php 
function my_theme_enqueue_styles() { 

    $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme. 

    wp_enqueue_style($parent_style, get_template_directory_uri() . '/style.css'); 
    wp_enqueue_style('child-style', 
     get_stylesheet_directory_uri() . '/style.css', 
     array($parent_style), 
     wp_get_theme()->get('Version') 
    ); 
    wp_enqueue_script('custom.js', get_stylesheet_directory_uri() . '/js/custom.js', array('jquery'), 1.0, true); 
} 
add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles'); 
?> 

機能ファイルの現在のコードです。誰にもアイデアはありますか?

答えて

0

wp_enqueue_styleは、ソースが提供されている(上書きしないでエンキューしている場合)スタイルを登録することを意味します。あなたの質問から、あなたはこの機能を使って上書きしようとしているのですが、それは明らかにそれが何でないかです。

1つの選択肢は、ファイルがインポートされた順序を確認し、以前にロードされていることを確認することです。これはテーマにどれだけのコントロールがあるかによっては必ずしも可能ではありません。

すべての場合に機能するもう1つのオプションは、オーバーライドすることです。オーバーライドを強制するには、最初にスクリプト/スタイルをデキューする必要があります。また、スタイルガイドに従ってください。特に、ヘルプを求めているときに、他の人があなたがしようとしていることを簡単に見られるようにします。ここにあなたのコードだ、クリーンアップおよびデキューを追加しました:あなたも上書きする場合

<?php 
require_once get_stylesheet_directory_uri() . '/lib/custom.lib.php'; 

add_action('wp_enqueue_scripts', function() { 
    // This is 'twentyfifteen-style' for the Twenty Fifteen theme. 
    $parent_style = 'parent-style'; 

    // Dequeue the parent 
    wp_dequeue_style($parent_style); 

    // Queue up our custom style 
    wp_enqueue_style($parent_style, get_template_directory_uri() . '/style.css'); 
    wp_enqueue_style(
     'child-style', 
     get_stylesheet_directory_uri() . '/style.css', 
     array($parent_style), 
     wp_get_theme()->get('Version') 
    ); 
    wp_enqueue_script(
     'custom.js', 
     get_stylesheet_directory_uri() . '/js/custom.js', 
     array('jquery'), 
     1.0, 
     true 
    ); 
}); 

もう1つ考えるべきことです。あなたがスタイルを完全に変えているなら、多分これは別のテーマです。スタイルを完全に変更していない場合は、元のCSSを含めて、スタイルの変更を加えたCSSを含めてもかまいません。

+0

主な問題は、custom.lib.phpが優先される必要があり、私が見たすべての回答がrequire_onceを実行することを示していますが、それはうまくいくが、必要なことはしていない。それでも、親テーマcustom.lib.phpの方が優先されます。 – saxon564

関連する問題