Getting redirect to happen before header output

Your method is called too late. I don’t know how you call this method but you need to run it before output is sent to the browser– usually that means before get_header(). There are a number of hooks that can be used. For example (from https://wordpress.stackexchange.com/a/131210/21376): add_action( ‘template_redirect’, function() { if (is_single()) { wp_safe_redirect(home_url()); exit; … Read more

Redirect if not logged in?

The is_login_page() function is taken from here function is_login_page() { if ( $GLOBALS[‘pagenow’] === ‘wp-login.php’ && ! empty( $_REQUEST[‘action’] ) && $_REQUEST[‘action’] === ‘register’ ) return true; return false; } function my_redirect() { //if you have the page id of landing. I would tell you to use if( is_page(‘page id here’) instead //Don’t redirect if … Read more

Unable to get wp_redirect() working after adding a CPT via the front end

You should keep the form on new-customer.php and set the form action to POST to another script (something like new-customer-process.php) and then paste your PHP code into that script. Essentially the user won’t know any different as they will be redirected back to the home page. To give you a little more information, the form … Read more

URL Redirect and Bulk Actions in wp_list_table

Understand hierarchy, You don’t need to redirect as form are posting values on same page. function process_bulk_action() { // Some security check code here // Get the bulk action $action = $this->current_action(); if ($action == ‘bulk_trash’) { // Code for the “delete process” $delete_ids = esc_sql($_POST[‘bulk-delete’]); //loop over the array of record ids foreach($delete_ids as … Read more

Custom pagination structure

After searching here and there, probably I found solution. (Don’t know if I am doing wrong in WP terminology!) Page was redirecting from …/page5 to …/page/5, because of redirect_canonical function resides in WordPress core. So I further searched for altering it by hook. Few people were saying remove redirect_canonical filter by adding this in code: … Read more

Load template inside a parent template

if ( condition ) { get_template_part( ‘path/to/template’, ‘mobile’ ); } else { get_template_part( ‘template’, ‘mobile’ ); // in rootpath } You can also intercept the behavior for get_template_part() with an action hook: // Source in get_template_part do_action( “get_template_part_{$slug}”, $slug, $name ); function wpse21352_template_part_cb( $slug, $name ) { switch ( $name ) { case ‘mobile’ : … Read more