Note that there are some explanatory texts on larger screens.

plurals
  1. POEnqueue script based on page condition
    text
    copied!<p>I'm trying to figure out how to enqueue files (javascript and styles) based on a condition- is_page() from within my plugin's config file. For a week now, I've been trying to find a working solution out of the myriads I've found online. </p> <p>Here's the original from the file:</p> <pre><code>public function enqueue_files() { wp_enqueue_script("jquery"); wp_enqueue_style("wpsqt-main",plugins_url('/css/main.css',WPSQT_FILE)); } </code></pre> <p>Here's what I attempted:</p> <pre><code>public function enqueue_files() { if ( is_page(xxx) ) { wp_enqueue_script("jquery"); wp_enqueue_style("wpsqt-main",plugins_url('/css/main.css',WPSQT_FILE)); } } </code></pre> <p>When I test <code>if ( is_page() )</code>, it removes the scripts and styles from the headers of all pages. However, when altering it to: <code>if ( !is_page() )</code>, it adds it back. Weird?</p> <ol> <li>Is there a way to do include the condition?</li> <li>Does the public function portion alter the way the condition is read?</li> <li>Is it possible to remove the enqueue from the plugin's config file and place it in my function.php file so whenever the plugin is updated, I don't have to make changes?</li> </ol> <p>Here's the file (the call to enqueue the file is at the very bottom): <a href="http://pastebin.com/sDt4sTCH" rel="nofollow">http://pastebin.com/sDt4sTCH</a></p> <p>I included the actual file so you can get the context it's used in. Thanks in advance!! <strong>EDIT</strong> better code format</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload