How to modify current page breadcrumbs markup

#68342
  • Resolved Jesus
    Rank Math pro

    Hi, I’d need to make a litle change in the breadcrumbs markup. The <span> tag marking the current page should include the attribute aria-current=”page” to improve accessibility.

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Alberto
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    You can use the following filter to modify the HTML code in your breadcrumbs so it is exactly as you want: https://rankmath.com/kb/filters-hooks-api-developer/#change-breadcrumb-args

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Hello Alberto, thanks for the answer.

    That code is clear to me, but I would need to target only to the last item of the breadcrumb, which is usually the current URL, to change the markup in that item only.

    Hello,

    To modify the last element you can do it as follows:

    /**
     * Filter to change breadcrumb html.
     *
     * @param  html  $html Breadcrumb html.
     * @param  array $crumbs Breadcrumb items
     * @param  class $class Breadcrumb class
     * @return html  $html.
     */
    add_filter( 'rank_math/frontend/breadcrumb/html', function( $html, $crumbs, $class ) {
    	// theme_breadcrumb_function();
           $customHTML = "YOUR HTML HERE";
          $html[count($crumbs)-1] = $customHTML;
    	return $html;
    }, 10, 3);

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘How to modify current page breadcrumbs markup’ is closed to new replies.