• Resolved berkmh

    (@berkmh)


    do you guys have a filter to control the schema output of 5.0? I only want the breadcrumbs schema running since I have hardcoded all other schema…

Viewing 1 replies (of 1 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    If you just want the breadcrumbs, you can use this:
    tsf()->breadcrumbs()->get_breadcrumb_list(); you’ll have to transform that list into a Schema, where url is the ListItem’s item, and name is name.

    e.g.:

    $list = tsf()->breadcrumbs()->get_breadcrumb_list();
    
    $list_items = [];
    
    foreach ( $list as $i => $item ) {
    	$list_items[] = [
    		'@type'    => 'ListItem',
    		'position' => $i + 1, // Let's not create 0
    		'item'     => sanitize_url( $item['url'] ),
    		'name'     => tsf()->filter()->sanitize()->metadata_content( $item['name'] ),
    	];
    }
    
    if ( $list_items ) 
    	// Pop off the last URL, so search engines will use the page URL instead.
    	unset( $list_items[ array_key_last( $list_items ) ]['item'] );
    
    	$schema = [
    		'@type'           => 'BreadcrumbList',
    		'itemListElement' => $list_items,
    	];
    }

    Note that you must wrap this in if ( function_exists( 'tsf' ) ) {} to prevent crashing when TSF is disabled.

    Alternatively, you can use the filter below to augment TSF’s Schema.org output to only provide breadcrumbs — however, I cannot promise it’ll work forever since I never considered your type of request. Still, you’re free to reach out for an updated version if necessary.

    add_filter(
    	'the_seo_framework_schema_graph_data',
    	function( $graph ) {
    
    		foreach ( $graph as $entity ) {
    			if ( isset( $entity['breadcrumb'] ) ) {
    				return $entity['breadcrumb'];
    			}
    		}
    
    		// Empty graph if there's no breadcrumb.
    		return [];
    	},
    );

    I hope this helps. Cheers!

Viewing 1 replies (of 1 total)
  • The topic ‘Schema filter’ is closed to new replies.