• Resolved U&I

    (@uandiweb)


    Hi,

    I see you have a sample snippet for adding code to the header as follow:

    add_action( ‘wp_head’, function () { ?>

    How can I change it to body?

    Thank you very much for the great plugin.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi @uandiweb,

    If you would like to add code to the end of the <body> section, you can replace that line with this:

    add_action( 'wp_head', function () { ?>

    That adds to the head section. New templates should support wp_body_open. That is primarily for JavaScript but can use also for other purposes. Old templates don’t support this.

    Plugin Author Shea Bunge

    (@bungeshea)

    Ah, my mistake. If you want to add code to the end of the <body> section, right before the </body> tag, you should actually replace it with this line:

    add_action( 'wp_footer', function () { ?>

    As @tapiohuuhaa said, if you have a theme which supports it, you can alternatively add code to the start of the <body> section, right after the <body> tag, you can use this as the first line:

    add_action( 'wp_body_open', function () { ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add Script to Body’ is closed to new replies.