0

I've been using Wordpress for a while, and I really like it \o/... I've written plugins for the Joomla platform but I'm sort of struggling getting going on the wordpress platform :

Here's my plan. I'm in the process of writing a plugin that uses Flash to allow the user to record audio from the soundcard (my idea is to allow the user to record a podcast through the web site).

I have a questions (so many questions...) but I'll go with these few :

I am using wp-enqueue to load the Javascript libraries into the page or post as it is loaded. Currently I'm using add_action('init', 'register_libraries'); to register the javascript libraries - and I think that works - but it also shows in the administration page (where this plugin won't be used).

So I had a look a the codex page and it suggests that I should be using init - it says that init is "Typically used by plugins to initialize". But that also includes the administration side, which I don't want for this plugin. Any suggestions what I should do instead?

In addition, and perhaps this should be a separate question - I wanted to load flash during the loading of the plugin - how should I do that - any ideas?...

I know... It's a bit noobish...

1 Answer 1

2

you should use wp_print_scripts hook for your scripts instead of init and in your callback make sure that you are not in the administration pages something like this:

add_action('wp_print_scripts','register_libraries');
function register_libraries(){
    if (!is_admin()){
     //enqueue your scripts here
    }
}

as for adding flash, that should be a separate question just make sure to add more details about it.

5
  • Any reason you're recommending using wp_print_scripts, rather than wp_enqueue_scripts? +1 for the if ( ! is_admin() ) suggestion, regardless. Feb 16, 2012 at 3:54
  • @ChipBennett good question, it would work either way but its not my favorite workflow, wp_print_scripts is the action that runs when scripts are output to the template. wp_register_script and wp_enqueue_script are functions for registering/enqueueing scripts to be output when wp_print_scripts runs. so in this point it makes no difference
    – Bainternet
    Feb 16, 2012 at 8:53
  • Thanks... i'll add the admin check into my code, and try the wo_print_scripts. I think there's a bit of reading for me to do through the codex... Feb 16, 2012 at 9:37
  • @Bainternet but you're enqueueing scripts; semantically that should be done at the hook for enqueueing scripts. Practically, it should be done there, just as a matter of considerate practice, so that there are still later hooks available to override the action. I treat wp_print_scripts as a last resort only. Feb 16, 2012 at 14:35
  • @ChipBennett that approach is correct in my book too but you still have a filter to remove scripts even at that point.
    – Bainternet
    Feb 16, 2012 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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