Categories: Wordpress

WordPress wp_redirect, no header and CSS style

Not so long ago, I showed how to use wp_redirect() in WP plugins without any problems.

After using that, I soon came to a problem. Like many of you, I also use custom CSS in the admin area for my plugins.

The problem was that after submitting the form, the CSS style for my plugin was lost.

Of course the reason for that is that I’m using noheader in the URL.

Not to fear, the solution is here. ;)

It’s pretty easy. All you need to do, is to add CSS style to admin_head action again and that’s it.

Here’s an example code:

function ltw_tes_output_style()
	wp_enqueue_style('wpr_test_stylesheet', WP_PLUGIN_URL.'/wp_redirect_custom_css/style_admin.css', array(), get_bloginfo('version'), 'all');
add_action("admin_head", 'ltw_tes_output_style');

if (isset($_GET['noheader']))
	require_once(ABSPATH . 'wp-admin/admin-header.php');

As you can see, I have added the function to the admin_head and the CSS style is outputted in the header HTML again.

I’ve also put together a simple example plugin that you can download and give it a test in your WP installation to see where the magic happens.

[download_source_code url=””]

Leave a Reply

Your email address will not be published. Required fields are marked *