Home / Admin / Remove #listItem from Breadcrumb schema
Duplicate Snippet

Embed Snippet on Your Site

Remove #listItem from Breadcrumb schema

This snippet removes #listItem from all the URLs in the Breadcrumb schema

Code Preview
add_filter('aioseo_schema_output', 'aioseo_schema_remove_list_item');
// Callback function to remove '#listItem' from URLs in BreadcrumbList
function aioseo_schema_remove_list_item($graphs) {
    // Loop through each element in the array
    foreach ($graphs as $index => $value) {
        // Check if the key '@type' is set and its value is 'BreadcrumbList'
        if (isset($value['@type']) && $value['@type'] === 'BreadcrumbList') {
            // Call the recursive function to remove '#listItem' from BreadcrumbList
            $graphs[$index] = aioseo_recursive_remove_list_item($value);
    return $graphs;
// Recursive function to traverse the array and remove '#listItem'
function aioseo_recursive_remove_list_item($array) {
    // Loop through each element in the array
    foreach ($array as $key => &$value) {
        // If the element is an array, recursively call the function
        if (is_array($value)) {
            $value = aioseo_recursive_remove_list_item($value);
        // If the element is a string and contains '#listItem', remove it
        elseif (is_string($value) && strpos($value, '#listItem') !== false) {
            $value = rtrim($value, '#listItem');
    return $array;


Add a Comment