Skip to content
Advertisement

Change Content of Page Depending on if User Access It via URL Bar vs. a Button on Website

I’m currently developing a website on WordPress

Is there a way, with either the use of JS or PHP, to make it so that when the user clicks an anchor tag within the website, they are taken to another page, but if they decide to go to that same page by typing the URL in the search bar, they are denied and the content displays a 404 message?

Example:

JavaScript
JavaScript

Advertisement

Answer

You can check if $_SERVER['HTTP_REFERER'] is set in case of a referrer from different page or not (direct access). You can also extend the check of this value to specific page(s), but you can start with:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement