Horje
History trail breadcrumb - Echo Page the user came from - Wordpress Solution
[Solved] - History trail breadcrumb - Echo Page the user came from - Wordpress Solution
Try following codes
I'd like to include in existing breadcrumbs, a link to point to the page user came from. Is this possible and any solutions for WordPress? What I have is:
<a href="#">Blog</a> | Current page
What I try to achieve is:
<a href="#">Link to the page/category/post user came from within the website [name of the page linked]</a> <a href="#">Blog</a> | Current page
I need to add this to the beginning of the existing Breadcrumb (will not interact though.)

Solution - 1

I'd suggest cookies approach, more-less like this:

<?php

if ( $_COOKIE['bread_type'] && $_COOKIE['bread_id'] ) :
	
$id = $_COOKIE['bread_id'];

switch($_COOKIE['bread_type'] ) {
	case 'single':
		$link_code = '<a href="'.get_permalink($id).'">'.get_the_title($id).'</a>';
		break;
	case 'page':
		$link_code = '<a href="'.get_permalink($id).'">'.get_the_title($id).'</a>';
		break;
	case 'single':
		$link_code = '<a href="'.category_link($id).'">'.category_title($id).'</a>';
		break;
}
endif;

echo $link_code;


global $post, $cat;

if (is_single()) :
	$type = 'single';
	$id = $post->ID;
else if (is_category()) :
	$type = 'cat';
	$id = $cat;
else if (is_page()) :
	$type = 'page';
	$id = $post->ID;
else :
	$type = false;
	$id = false;
	
endif;
	
setcookie('bread_type', $type);
setcookie('bread_id', $id);

?>


Solution - 2

if you mean to say the page user came from then Michael Fields is right though i haven't use the wp_get_referer() it might be equal to:

<?php echo $_SERVER['HTTP_REFERER']; ?>


Solution - 3

[[LINK href="http://codex.wordpress.org/Function_Reference/wp_get_referer"]]wp_get_referer()[[/LINK]] would be a good place to start.

Date: 2022-10-21 05:19:00
Category: Wordpress
More for You