Schema.org, top snippets for your portfolio or blog with spatie/schema-org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Changes the search slug to /search/ for the JSON+LD output | |
*/ | |
function yst_change_json_ld_search_url() { | |
return trailingslashit( home_url() ) . 'search/{search_term}'; | |
} | |
add_filter( 'wpseo_json_ld_search_url', 'yst_change_json_ld_search_url' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'get_header', 'themeprefix_cpt_microdata' ); | |
//Change microdata for events custom post type | |
function themeprefix_cpt_microdata() { | |
if ('event' == get_post_type()) {//change to your cpt | |
//add in the microdata changes | |
add_filter( 'genesis_attr_entry', 'themeprefix_genesis_attributes_entry', 20 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Remove the schema markup from an element | |
function mg_schema_empty( $attr ) { | |
$attr['itemtype'] = ''; | |
$attr['itemprop'] = ''; | |
$attr['itemscope'] = ''; | |
return $attr; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'genesis_attr_content', 'yoast_schema_empty', 20 ); | |
add_filter( 'genesis_attr_entry', 'yoast_schema_event', 20 ); | |
add_filter( 'genesis_attr_entry-title', 'yoast_itemprop_name', 20 ); | |
add_filter( 'genesis_attr_entry-content', 'yoast_itemprop_description', 20 ); | |
add_filter( 'genesis_post_title_output', 'yoast_title_link_schema', 20 ); | |
/** | |
* We'll use the post info output to add more meta data about the event. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create shortcode to list videos visually on video resource page with schema | |
add_shortcode( 'videos', 'videos_shortcode' ); | |
function videos_shortcode( $atts ) { | |
ob_start(); | |
extract( shortcode_atts( array ( | |
'category' => '', | |
'quantity' => -1, | |
'p_id' => '' | |
), $atts ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add Custom Micro Data To Specific Pages In Genesis using Yoast Genesis Schema Helper Script | |
add_filter( 'genesis_attr_body', 'custom_microdata_schema' ); | |
function custom_microdata_schema( $attr ){ | |
if( is_front_page() ){ | |
add_filter( 'genesis_attr_entry', 'yoast_schema_product', 20 ); | |
add_filter( 'genesis_attr_entry-title', 'yoast_itemprop_name', 20 ); | |
add_filter( 'genesis_attr_entry-content', 'yoast_itemprop_description', 20 ); | |
add_filter( 'genesis_post_title_output', 'yoast_title_link_schema', 20 ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Render the schema graph for the acf/gb-faq block. | |
* | |
* @param array $graph Schema data for the current page. | |
* @param WP_Block_Parser_Block $block The block data array. | |
* @param Meta_Tags_Context $context A value object with context variables. | |
* | |
* @return array Our Schema graph. | |
*/ |