Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

ced1870 on "add js only if condition is true"

$
0
0

Hi
I'm developping my plugin and it works :), that is the good news
Now I would like to make it correctly.
1/ I have a fonction that check if a word exist in the content:

add_filter('the_content', array( $this, 'searchkey'));

2/ I have an action to load my CSS and JS files

add_action('wp_enqueue_scripts', array( $this, 'load_assets_files'));

The problem here is that even if my word is not found in the content, the CSS and JS files will be loaded. I want to
if (word is found) {
load my js and css
}

but if I use <script type="text/javascript"> in my condition, it will be added for each post content. It needs to be added into the head.
If I use a "add_action('wp_head')" into my condition which is in the_content filter, then it does not work.


Viewing all articles
Browse latest Browse all 8245

Trending Articles