[wp-hackers] Just a basic "how can this be accomplished?" question.
Nop
nopalot at iplace.at
Sun Feb 5 21:41:33 UTC 2012
Hi Nathaniel,
thank you very much for the detailed answer!
It works perfect! I ended up with 7 lines of code and 42 lines of
comments :)
Thanks again!
On Sun, 2012-02-05 at 11:39 -0500, Nathaniel Taintor wrote:
> First, you will have to know the ID of the particular page you want to
> modify. You can create a settings page for users to select that page, or
> calculate it however you need to. Store that as a plugin option to save the
> trouble of calculating that on every page load.
>
> Hook into wp_enqueue_scripts. That's the best place to set scripts and
> styles to enqueue. You can enqueue the scripts using wp_enqueue_script and
> wp_enqueue_style, and generate the variables to pass to your javascript
> using wp_localize_script.
>
> Your function will look something like this (I'm assuming the page you want
> to modify is stored in a function called 'this_plugin_page')
>
> add_action( 'wp_enqueue_script', 'my_plugin_enqueues' );
>
> function my_plugin_enqueues() {
> $plugin_page = get_option( 'this_plugin_page' );
> if ( !is_page( $plugin_page ) )
> return;
> wp_enqueue_script( 'myscript', plugins_url('/js/newscript.js',
> __FILE__) );
> $script_vars = array( 'this' => 'that', 'foo' => 'bar' );
> wp_localize_script( 'myscript', 'scriptVars', $script_vars );
> wp_enqueue_style( 'mystyle', plugins_url('/css/newstyle.css',
> __FILE__) );
> }
>
>
> Nathaniel Taintor, Designer/Developer
> *Golden Apples Design*
> http://goldenapplesdesign.com
>
> @GoldenApples | 717.434.3226
> goldenapplesdesign at gmail.com
>
>
>
> On Sun, Feb 5, 2012 at 8:43 AM, Nop <nopalot at iplace.at> wrote:
>
> > Hello,
> > could you please help me by supplying a short sketch for a plugin that
> > performs the steps described below?
> > What I need is just a short list of steps that are required. Something
> > in the form of:
> > 1. do this to accomplish....
> > 2. use this function for that...
> > 3. do/use this because...
> >
> > Here's what the plugin should do:
> > 1. Add a global javascript variable to the output html page.
> > 2. Add/Load a javascript file at the output html page.
> > 3. Add/Load a css file at the output html page.
> > 4. Do the above steps only at one particular wordpress page.
> > 5. Do it in the fastest possible way, but I do NOT like to modify any
> > wordpress or template files, as I'm aiming for a stand alone plugin.
> >
> > Knowing what steps I have to do and in what order they have to be done
> > to accomplish this plugin would help me very much.
> > I'm grateful for any advice,
> > Thank you!
> >
> >
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list