WordPress.org

Ready to get started?Download WordPress

Forums

hook the body tag (1 post)

  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;
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic