Saturday, September 28, 2013

WordPress: Removing the default 28px margin forced into the page by default

By default, WordPress adds a 28px margin to your pages by outputting the following block of css in the head element, for a logged in user :

<style type="text/css" media="screen">
 html { margin-top: 28px !important; }
 * html body { margin-top: 28px !important; }
</style>

add_theme_support( 'admin-bar', array( 'callback' => '__return_false') ); 

Just make sure you add the above method call as is. Don't include it in an action hook such as init and any other action that is called at a stage past the init phase. The documentation too makes this observation:

If attached to an action hook, it should be after_setup_theme. The init action hook may be too late for some features.

Reference: http://codex.wordpress.org/Function_Reference/add_theme_support