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!
7 Responses
While this is a great recipe, we really should be using
wp_enqueue_script()when adding JavaScript.@Justin Tadlock: You’re right, wp_enqueue_script() seems more appropriate for adding Javascript. However, the hook is still great for including stylesheets
There’s
wp_enqueue_style()for including stylesheets as well.Stylesheets aren’t as important using this method, but using
wp_enqueue_script()is important for adding JS.So
wp_enqueue_script()would replace what then?@WP Cult
It would replace all everything. See the WP Codex article on wp_enqueue_script.
Trackbacks: