Redirect based on referer using Advanced Custom Fields

Try the template_redirect hook function portal_protection() { if ( get_field(‘enable_portal_protection’) && !current_user_can(‘administrator’) ) { $referring_url = get_field(‘referring_url’); $redirect_url = get_field(‘redirect_url’); $referer = $_SERVER[‘HTTP_REFERER’]; if ( $referer != $referring_url) { wp_redirect( $redirect_url ); exit; } } } add_action( ‘template_redirect’, ‘portal_protection’ ); Also use wp_redirect. it’s the WordPress way of redirecting.

How to display the contents of URL1 when user visits URL2

Have WordPress (which creates the web server responses) respond with a redirect (via a call to wp_redirect()). Put as the first thing in header.php global $post; if( needs_replacement( $post ) ) { $from_url = create_url( $post ); wp_redirect( $from_url ); exit(0); } require_once( get_template_directory() . ‘/page.php’ ); ?> (Note that you have to this first … Read more

How can I make custom page templates work on child theme?

Edit: I see you’ve answered your own question, but the answer you provided seems dubious to me, so I’m going to post this anyway. A child theme needs a few key elements to work: a style.css with header information (including Template: parent-theme-name), a functions.php file (where you can enqueue the parent theme’s stylesheet), and activation … Read more

Set page template automatically according to parent slug

You can override the hierarchy and load a specific page template via the page_template filter. The fastest way is to identify the parent page by ID: function wpd_page_template_filter( $template ){ $page = get_queried_object(); if( 42 == $page->post_parent ){ // en page has ID of 42 $template = locate_template( ‘page-en.php’ ); } return $template; } add_filter( … Read more