WordPress.org

Ready to get started?Download WordPress

Forums

hook the body tag (2 posts)

  1. leisegang
    Member
    Posted 1 year ago #

    is there any way of using this code only on the frontend of wordpress and not in the backend?

    I get "YOUR INSERTED HTML GOES HERE" in the admin area also. which i dont want but i need to "hook" the body tag.

    <?php
    add_filter('template_include','yoursite_template_include',1);
    function yoursite_template_include($template) {
    	ob_start();
    	return $template;
    }
    add_filter('shutdown','yoursite_shutdown',0);
    function yoursite_shutdown() {
    	$insert =  "[YOUR INSERTED HTML GOES HERE]";
    	$content = ob_get_clean();
    	$content = preg_replace('#<body([^>]*)>#i',"<body$1>{$insert}",$content);
    	echo $content;
    }
    ?>
  2. s_ha_dum
    Member
    Posted 1 year ago #

    You can always check to see if it is an admin page.

    if (is_admin()) {
        // do
    } else {
       // or do not
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.