How to: Integrate files on your blog header

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');

Credits goes to X-OR for this awesome recipe!

Leave a Comment

* Name, Email, Comment are Required