Integrate files on your wordpress blog header

December 7, 2008 · Print This Article

When developping a WordPress plugin or widget, you sometimes need to add files as such as CSS or Javascript in the theme header.

But how to do it when you can access the theme file? Here’s a simple way to add anything in the blog header without editing header.php.

The principe is simple: You first got top create a function that will simply print the required files. Then, you got to hook it to the wp_head() WordPress function, by using the add_action() function.

function GetLastPostName_head()
{
echo '<script type="text/javascript" src="'.get_settings('siteurl').'/wp-content/plugins/slidelastposttitle/mootools.js"></script>';
echo '<script type="text/javascript" src="'.get_settings('siteurl').'/wp-content/plugins/slidelastposttitle/blackbox.js"></script>';
}
add_action('wp_head', 'GetLastPostName_head');


Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.