How to add #anchor at the end of the WordPress URL
-
I have WordPress and I would like that all visitors who access my site by searching in google (traffic source), go directly to a specific part of the page (focus).
To focus on this part, I need to include the anchor at the end of the url: #welcome-source-google https://example.com/category/page-or-post/#welcome-source-google
I think I need to insert this code, probably in functions.php:
function organic_source_anchor() { if (preg_match('/(www\\.)?google\\./', $_SERVER['HTTP_REFERER'])) { wp_redirect( get_permalink( $postID ) . '#welcome-source-google' ); exit; } add_action( 'template_redirect', 'organic_source_anchor' );
I got this code by researching, but since I am not a programmer, I believe there are several errors or maybe I need to put the code out of functions. A problem that happens is that I didn’t want to disable the cache, as this frame appears to all visitors, but if the source is from google, I wanted the focus on the part this page.
- The topic ‘How to add #anchor at the end of the WordPress URL’ is closed to new replies.