• Resolved chasewsg

    (@chasewsg)


    I need help urgently to add articleBody structured data to each page/post.

    How can I add to the existing ld+json script through custom field for each page/post?

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

    (@hishaman)

    You can use a filter to extend schema output, this example code should give you an idea of how to do that.

    And, well… here is the actual code that you can use:

    add_filter('schema_output', 'schema_wp_extend_output_articleBody_98738765');
    /**
     * Add articleBody to Schema Output
     *
     * @since 1.0
     */
    function schema_wp_extend_output_articleBody_98738765( $schema ) {
    	
    	global $post;
    	
    	if ( empty($schema) ) return;
    	
    	// Add articleBody
    	// $schema['articleBody'] = 'This is the article body text...';
    	//
    	// So, you can do something like this to pull value from post meta 
    	//
    	// Change YOUR-KEY with the actual post meta key where value is stored
    	//
    	$article_body = get_post_meta( $post->ID, 'YOUR-KEY', true );
    	
    	if ( isset($article_body) ) {
    		 $schema['articleBody'] = $article_body;
    	}
    	
    	return $schema;
    }

    Link to code gist.

    In Addition: The reason why this isn’t part of the plugin core functionality is that, Google do not have it as a requirement. Also, this will lead to saving the whole post content in the _schema_json post meta field, which has the json-ld output for fast query by the Schema plugin.

    I hope this helps.

    • This reply was modified 7 years, 5 months ago by Hesham Zebida. Reason: provide more details
    Thread Starter chasewsg

    (@chasewsg)

    Thank you so much for the speedy reply!

    I have implemented it and it works perfectly, thank you.

    I needed articleBody for my site so was looking for this solution, thanks again!

    Plugin Author Hesham Zebida

    (@hishaman)

    Glad I could help.

    I am not sure if this has to be included in the plugin, I will check and will add it to the plugin if it’s applicable.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post Meta Box add articleBody’ is closed to new replies.