1

それを拡張する別のプラグインを作成して、既存の WP プラグインを変更しています。プラグインをオーバーライドする CSS を書きたいと思います。ただし、スタイルシートをキューに入れようとすると機能しません。includes()に単純なフォームを追加し、変更を確認するために赤い単語のスタイルを設定しようとしたため、機能しないことはわかっています。なぜこれが機能しないのですか??

plugins_loaded注 -コーデックスで読んだアクション フックを使用していwp_enqueue_scriptます。したがって、エンキューのタイミングがずれているとは思いませんが、WP 開発は初めてなので、間違っている場合は修正してください。

更新- 以下の更新された CSS コードを参照してください。#id セレクターはテキストを赤く着色していませんでした、 p (段落セレクター) を追加すると機能しました。どちらのセレクターも単独では機能せず、両方を追加した場合にのみ機能しました。どうしてこれなの?

find-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>
4

1 に答える 1