• Resolved wasanajones

    (@wasanajones)


    Thanks for your great plugin.

    I’m desperately trying to come up with a way to add organization schema to individual CPT. shortcode would be ideal, and/or using WP visual editor.

    Anyway to make schema plugin do this?

    regards

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Hesham Zebida

    (@hishaman)

    Hi, I am not sure if I got this right, but the Schema plugin output the Organization markup on the front page of the site.

    I’ve made a few changes to the plugin, and will release an update in a few, look for version 1.6.9.2, the code below won’t work on older version of the plugin. So, please make sure to update the plugin on your website first before using this code.

    You can use something like this to override its normal behaviour:

    // First: we remove the Knowledge Graph markup
    remove_filter( 'schema_wp_filter_output_knowledge_graph', 	'schema_wp_do_output_knowledge_graph' );
    // Second: we output the Knowledge Graph markup everywhere on the website
    add_filter( 'schema_wp_filter_output_knowledge_graph',		'schema_wp_do_output_knowledge_graph_71837615376457563' );
    /*
    * Output Knowledge Graph markup, this function overrides Schema output
    * so we can control where it should shown (not only the front page)
    *
    * @since 1.6.9.2
    */
    function schema_wp_do_output_knowledge_graph_71837615376457563( $knowledge_graph ) {
    	
    	if ( ! class_exists( 'Schema_WP' ) ) 
    		return; // Schema not present
    	
    	return $knowledge_graph;
    }

    You can then use conditions and have control over where the Knowledge Graph will show, example on certain pages or post types.

    Alos, here is the Code Gist.

    Thread Starter wasanajones

    (@wasanajones)

    thank you for incredible response.

    my only issue here is that I need different schema presented for each individual CPT rather than one organization for the whole site (ie. they are directory listings) –

    another thing that would come up in Google structured data testing tool would be the required image would need to be also present (default featured image with schema if none present)

    I know that wasn’t the original intent of your plugin – but I hope you can see the value of being able to assign independent schema per post

    THANKS

    Plugin Author Hesham Zebida

    (@hishaman)

    Ah ok!

    This is absolutely possible via filters, but it will require some additional coding to:

    Add new schema.org type.
    – Create new custom post meta fields for the new type.
    Override schema.org markup output to reflect changes.

    P.S. Check the links in the points above, and find out more snippets in these gists at GitHub..

    The thing here is Schema plugin won’t have this code, this is because the goal of the plugin is to support a basic setup of WordPress. Other features shall be provided via the Theme, or another plugin extension.

    I am working on creating a couple of useful extension, which will allow you to add more schema.org types. I am trying my best to make this happen soon! (That’s why I am planning to offer these as paid extensions)

    For the default image, you can install the Schema Default Image plugin. Or if you prefer a function:

    function schema_wp_set_default_image_12345( $json ) {
    	
    	// If image is already defiend,
    	// return our $json array and do not do anything
    	if ( isset($json['media']) && ! empty($json['media']) ) return $json;
    	
    	// There is no image defined in Schema array, 
    	// set default ImageObject url, width, and height
    	$json['media']['@type'] = 'ImageObject'; // schema type, do not chage this!
    	$json['media']['url'] = 'https://default-image-url.png'; // set default image url
    	$json['media']['width'] = 720; // set image width
    	$json['media']['height'] = 400;	// set image height
    	
    	return $json;
    }
    add_filter('schema_json', 'schema_wp_set_default_image_12345');

    I hope this helps.

    • This reply was modified 7 years, 6 months ago by Hesham Zebida. Reason: add resources
    Thread Starter wasanajones

    (@wasanajones)

    great support, thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Organization schema on individual Custom Post Type’ is closed to new replies.