Welcome to Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy

Create Shortcode for WordPress Website

Create Shortcode for WordPress Website

				
					<?php

add_shortcode('breadcrumbs', 'breadcrumbs_shortcode');

function breadcrumbs_shortcode()
{
    global $post;
    $post_slug = $post->post_name;

    $breadcrumbs_url = '/article';

    $term_obj_list  = get_the_terms( $post->ID, 'type' );

    $url_string = '
        <a style="color: var( --e-global-color-secondary );" href="/">
            Home
        </a>
    ';

     foreach($term_obj_list as $term) {

        $breadcrumbs_url .= '/'.$term->slug;

        $url_string .= '
            <a style="color: var( --e-global-color-secondary );" href="'.$breadcrumbs_url.'">
            <span class="breadcrumbs-separator">»</span> '.$term->name.'
            </a>
        ';
     }

     $url_string .= '
        <a style="color: var( --e-global-color-primary );">
            <span class="breadcrumbs-separator">»</span> '.$post->post_title.'
        </a>
    ';

     echo $url_string;
}

?>
				
			

Create Shortcode that we need to used in website where we need breadcrumbs

				
					[breadcrumbs]
				
			

Drop your queries

Table of Contents

Have A Project In Mind? Let's Get To Work