I’m using WordPress with Elementor, I want a certain page to be accessible only if it comes from a certain url. I saw from other answers in similar questions that I can use this:
add_action( 'template_redirect', 'wpse15677455_redirect' );
function wpse15677455_redirect() {
$value = ('https://mywebsite.com/quotaton/') ;
if (!is_page(555) & wp_get_referer() !== $value ) {
wp_safe_redirect( get_home_url() );
}
};
I tried using this in the function.php of the theme but it returns the error "Unable to communicate with server to check for fatal errors". I tried with all plugins deactivated except elementor but same result.
I tried without the add_action call but, despite not giving errors, it also does nothing. I can’t seem to find the right place/way to use this function.
3
Answers
is_page(‘contact’) => ‘contact’ is page slug.
is_page(150) => ‘150’ is page ID.
Trying out the code, I believe the problem is that you’re missing a single ampersand(&) for the
And
operator. Also, ifis_page
is used to check for the "certain page", maybe thenot
(!) operator isn’t necessary…If the link that has to be redirected comes from a page, you could use a redirection plugin like this one: https://it.wordpress.org/plugins/page-links-to/
Once activated you just edit the page you want to be redirected inserting the correct link in the page links to field.