PDA

View Full Version : WP plugin question


Golgotha
01-31-2008, 06:20 PM
I'm creating my first Wordpress plugin. It's going good.
My question is getting the JS and CSS files written in the head.

I have used this code:


add_action('wp_head', 'addHeaderCode');
function addHeaderCode() {
echo "\n".'<!-- Start Obama2008 -->'."\n";
echo '<link type="text/css" rel="stylesheet" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/obama2008ribbon/obama2008ribbon.css" />' . "\n";

wp_register_script('obama2008ribbon', get_bloginfo('wpurl') . '/wp-content/plugins/obama2008ribbon/obama2008ribbon.js');
wp_print_scripts('obama2008ribbon');

echo '<!-- End Of Obama2008 -->'."\n";
}


This code WORKS, but is this the best way to do it?

SarahG
02-02-2008, 08:28 AM
Looking on the action hook reference it looks like a perfectly fine use to me - Plugin API/Action Reference WordPress Codex (http://codex.wordpress.org/Plugin_API/Action_Reference)

Liza
02-04-2008, 10:10 PM
Seeing you doing your plugin really inspries me to try out these additions to my Word Press blog. All the best, I saw your other post where it is actually working.