You can use wp_get_referer();
to get a URL of previous page from where user came. Then get the last slug part of the URL. Then compare if the slug matches with slug of your custom search-result page template. Then you can decide whether to show or not to show ‘Back to search results’ link. Please try below code and feel free to update as intended:
<?php
$ref_url = wp_get_referer();
$results = explode("https://wordpress.stackexchange.com/", trim($ref_url,"https://wordpress.stackexchange.com/"));
if(count($results) > 0){
//get the last record
$last_word = $results[count($results) - 1];
}
if ( $last_word == "about" )
echo "<a href="https://wordpress.stackexchange.com/questions/212927/$ref_url">Back to search results</a>";
?>
Related Posts:
- is_page_template not working
- When is get_template_part() preferable to simply using the template.php files?
- Variable use in get_template_part
- Store Page Template Files in a Subfolder
- How to show a post single post in page template
- Create a new template for twentytwelve
- Video Background – (php & css) – generating 404 error on page load – WordPress Theme File Structure Help
- is_page_template & is_page in functions.php not working
- Created custom post type but selected template not staying selected
- Why is POST’ing to my WP page template producing a 404?
- get page title, url and excerpt of a page
- Are page/post IDs unique across a whole network?
- Theme’s page.php and index.php template files are confusing me
- Grabbing the page template name?
- Adding the Admin Bar to a page with a custom template
- wp_title() handling of author page
- Why am I getting syntax error, unexpected ‘endwhile’ (T_ENDWHILE) in this template? [closed]
- How to edit 404 content via wp editor?
- wp_redirect() does not work in custom template file
- Remove all theme CSS & JS from wp_head (but only for 1 page template)
- Programatically changing template of a page
- WordPress can’t find IXR_Client
- Creating a new page template
- Unexpected results with conditionals inside template part
- Visual Editor Templates
- Creating a custom archive template that sorts post by date
- Pre get posts where template is not equal to one specified?
- Change content of page in child theme using plugin
- Can two custom templates be used to create a single page?
- Use the_title_attribute() for the WHERE parameter in a page template
- How to check if a specific page uses a page template?
- Conditional get template part
- Cant remove line that appears above page content
- Trying to return list of child pages for a template
- Page template without header & footer
- Page template for blog not working
- I want to duplicate homepage for all my pages
- WordPress showing 404 page template for unpublished posts
- Change Post Template based on post meta?
- How to rewrite title- and meta-description templates for page templates in Yoast Plugin [closed]
- Adding a Menu Page to The Dashboard
- !is_page_template not working with && operator
- Cleaner way to define multiple variables for is_page_template()
- Is there a way to create a template that does not have the site styling associated with it?
- page shows 404 on form submit
- Is it possible to add a child post into the parent page?
- Is it okay to use page template as contact page? [closed]
- Including facebook.php in a wordpress page template?
- is_front_page and is_home are not working in page.php
- changing background color depending on parent page
- How to build a PDF repository in WordPress
- Page with posts from category doesn’t work
- Why is a renamed custom template file still showing up in the template dropdown menu?
- Page template added via plugin not saved in Gutenberg
- Display ACF if parent page has specific template
- How can I load 2 random pages?
- Creating page & post templates without template file
- Blog page wont use blog-template.php
- Delete post: 2 wp_redirect if pages are different
- The best way to create pages like an ‘about’, ‘contact’ and etc [closed]
- Image not showing on page template in Twenty Fifteen-theme
- Function to load correct CSS for Template not working
- Change page template programmatically inside foreach
- Limit page template choice by page title or ID?
- WordPress custom login and register page problem?
- Using conditional statements in place of custom Page templates
- Controlling the Admin panel for page templates
- Page Templates automatically showing index page contents?
- Find php file anywhere in folder and subfolder from template
- different sidebars depending on template (is_page_template is not working)
- Create Page with Pagetemplate and get a post_type_object->template
- Inserting article:tags meta in html head-element, using get tags, no wp_head
- Set page title in WordPress with PHP
- How to allow user to select page template from front end?
- send page ID’s to another template
- Converted HTML5 to WP, How to apply converted classes to new pages (after conversion completed)
- Is there a universal slug for static homepage?
- Custom page template displays the archive template
- Target pages using Woo Commerce single product page template
- require happens out of order
- Using a page-template to restrict access based on IP (Frontend)
- Need help in creating splash intro page using custom page template
- how to get the title, description, pictures on the page?
- Show all images attached to posts as a gallery page?
- Page Template CSS file not loading
- Adding secondary featured image for page_for_posts
- What is the best way to create very custom campaign pages?
- Decision about page templates for static pages
- Loading custom page template on a one page website
- Custom page Template and Script as a Plugin
- Custom Forget Password page
- Using page template as Static Front Page
- Why do some pages on my site use the previous theme?
- How to make page template with admin able to select NextGen Galleries to be part of the layout?
- Showing sidebar-2 on custom template page
- How to move from page template to page template
- Background of default template showing instead of the background of custom page template
- Videopress Short Tags not working when pulling page into template
- Add a title to ACF form from frontend
- How do I update the SEO information on dynamic pages being generated from template_include?