0

I know this question has been asked many times but my requirements is bit different. Actually i want to add custom css/js to a particular template. First i show you my folder structure - enter image description here I do have a TradePartners folder on root which further contains css/js files inside css/js folder. Moreover this(TradePartners) folder contains a trade.partners.php file where i want to add these two css/js file but whenever i put css code inside css file it throws away css code at the top of whole site and js also does not work. Now i send you php code.

enter image description here

So now can please someone let me know how to add these files.

Thanks in advance

0

You have defined your becomeTradePartner function as static.

So try the following method to call it.

add_action( 'wp_enqueue_scripts', 'TradePartner::becomeTradePartner' );
1
  • But why to call becomeTradePartners function because it is already inside the class constructor so as soon as i will create the object of the class, which i have done at the bottom(not visible in screenshot), this function will be called automatically. Moreover, as long as i know static keyword does not affect in this case because i am not calling this function inside or outside the class.
    – Vipin
    Jun 21 '17 at 2:47
0

With static functions, you can add the action with __CLASS__ instead of $this:

add_action('wp_enqueue_scripts', [__CLASS__, 'becomeTradePartner']);

2
  • But why to call becomeTradePartners function because it is already inside the class constructor so as soon as i will create the object of the class, which i have done at the bottom(not visible in screenshot), this function will be called automatically. Moreover, as long as i know static keyword does not affect in this case because i am not calling this function inside or outside the class
    – Vipin
    Jun 21 '17 at 2:47
  • the add_action line for 'wp_enqueue_scripts' indeed is inside the constructor. But the function which is called for that hook is becomeTradePartner. From the codex: add_action( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 ) developer.wordpress.org/reference/functions/add_action That callable function for a function within the class is as we've already specified.
    – Brian
    Jun 21 '17 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.