×
  • Shared Hosting

    Fast reliable and affordable cPanel Web Hosting from $2.99 per month.

  • Reseller Hosting

    Multiple websites? No problem with our multi-site hosting package. From $5.99 per month.

  • Annual Hosting

    Save money on web hosting by paying annually. Starting at $29.99 per year.

  • VPS Servers

    Need more power and resources? Choose our VPS server, only $7.99 per month.

  • FREE HOSTING PLAN

    Ideal for students and unemployed.

    Register

PHP script to create waypoint navigation breadcrumbs

01/06/2022 | |0 comment

Breadcrumbs are a form of navigation used in web pages and websites. They are usually found at the top of the page (and sometimes the bottom) and are used to help visitors find their way around the website. In SEO terms, breadcrumbs are a way to help search engine spiders better understand the structure of a website and provide them with an easier way to crawl the pages.

They also help users to quickly find their way back to the main page of the website if they have clicked on a link in the navigation bar. Breadcrumbs can also be used to indicate the current page the user is on and make it easier for them to find their way back to a previous page.

Below is a PHP script to create waypoint navigation breadcrumbs

<?php 
 
// Create a function to generate dynamic breadcrumbs 
function generate_breadcrumb() { 
     
    // Set the initial parameters 
    $home_url = 'http://www.example.com/'; 
    $breadcrumb_separator = ' > '; 
     
    // Get the current page URL and parse it 
    $current_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 
    $url_components = parse_url($current_url); 
    $path = $url_components['path']; 
     
    // Create an array of the individual elements of the path 
    $path_elements  = explode('/', $path); 
     
    // Initialize an empty breadcrumb variable 
    $breadcrumb = '<a href="' . $home_url . '">Home</a>' . $breadcrumb_separator; 
     
    // Loop through the path elements and add each one to the breadcrumb 
    foreach($path_elements as $element) { 
         
        // Ignore empty elements 
        if(!empty($element)) { 
             
            // Get the title of the page from the database 
            $page_title = get_page_title($element); 
             
            // Generate the HTML for the breadcrumb link 
            $breadcrumb .= '<a href="' . $home_url . $element . '">' . $page_title . '</a>' . $breadcrumb_separator; 
        } 
    } 
     
    // Return the generated breadcrumb 
    return $breadcrumb; 
} 
 
// Function to get the title of a page 
function get_page_title($page_name) { 
    // Get the page title from the database 
    // Return the page title 
} 
 
// Generate the dynamic breadcrumb 
$breadcrumb = generate_breadcrumb(); 
 
// Print the breadcrumb 
echo $breadcrumb; 
?>

 

Chris

Freelance Technical SEO with - https://sitebee.co.uk