1

I have the following php code:

add_shortcode("hello","hello_func");
function hello_func(){
    add_action("wp_head","styles");
    add_action("wp_footer","scripts");
}
function styles{
    echo "<style>blahblahblah</style>";
}
function scripts{
    echo "<script>blahblahblah</script>";
}

For some reason, the scripts will be loaded into the footer, but the styles will not be loaded into the footer. Can anyone help?

Jordan Halaby
  • 11
  • 1
  • 2

2 Answers2

2

Try using wp_enqueue_script or wp_enqueue_style. This is normally the best way to add styles or scripts to WordPress. You can also pass a parameter in the wp_enqueue_script function to add the script to the footer.

Nick
  • 1,157
  • 1
  • 8
  • 13
1

Maybe do a

return "<style>blahblahblah</style>"; 

(guess)

dynamic
  • 46,985
  • 55
  • 154
  • 231
  • The wp_head action hook is triggered within the section of the user's template by the wp_head() function. Although this is theme-dependent, it is one of the most essential theme hooks, so it is widely supported. This hook provides no parameters. You use this hook by having your function echo output to the browser, or by having it perform background tasks. Your functions shouldn't return, and shouldn't take any parameters. http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head – Xman Classical Mar 07 '14 at 06:50