• Please help me dear , i am publish new updates by custom wordpress post on liveblog. i am trying many time but liveblogposting schema not working ,

    liveblogupdate posts not showing in wp head, please check my code .

    how to fix this error , please check my code and reply fast please..??

    
    add_action("wpseo_head", function($post) {
        
      date_default_timezone_set('Asia/Kolkata');
      $post_id = $post->ID;
      $published = $post->post_date;
      $modified = $post->post_modified;
      $date_atom = DATE_ATOM; //"Y-m-d\TH:m:s+G:i";
    
      $event_start = get_post_meta($post->ID, 'event_start', true);
      $event_end = get_post_meta($post->ID, 'event_end', true);
    
      $post_args = array(
          'post_type' => 'liveblog',
          'post_status' => 'publish',
          'meta_key' => 'liveblog_parent',
          'meta_value' => $post_id,
          'posts_per_page' => 1,
      );
      $lives = get_posts($post_args);
    
      if (count($lives) > 0) {
          $live = current($lives);
          if (!empty($live->post_modified)) {
              $modified = $live->post_modified;
          }
      }
    
      $excerpt = wp_strip_all_tags(get_the_excerpt($post_id));
      $excerpt = substr($excerpt, 0, 150);
      $excerpt =  get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true);
        
        $meta['liveBlogUpdate'] =     $lives = get_posts($post_args);
    
    $lives = array(
                    '@type'            => 'BlogPosting',
                    'headline'         => get_the_title(),
                    'url'              => $entry_url,
                    'mainEntityOfPage' => $entry_url,
                    'datePublished'    => get_the_date( 'c' ),
                    'dateModified'     => get_the_modified_date( 'c' ),
                    'articleBody'      => array(
                        '@type' => 'Text',
                    ),
                );
    
    ?>
            <script type="application/ld+json"><?php echo wp_json_encode( $metadata ); ?></script>
    <?php
        
    $metadata = [
      "@context" => "https://schema.org",
      "@type" => "LiveBlogPosting",
      "name" => "storename",
      "image" => "https://staticqa.store.com/wp-content/themes/faf/images/store-logo.png",
      "@id" => $storeid,
      "url" => "",
      "telephone" => $storephone,
    ]
                    
    ?>
            <script type="application/ld+json"><?php echo wp_json_encode( $metadata ); ?></script>
    <?php
    }); 

    it’s working on head , but update posts not showing on schema

    
    <script type="application/ld+json">{"@context":"http:\/\/schema.org","@type":"LiveBlogPosting","name":"storename","image":"https:\/\/staticqa.store.com\/wp-content\/themes\/faf\/images\/store-logo.png","@id":null,"url":"","telephone":null}</script>
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You’re outputting $metadata before it’s defined. Move the script tag output down to below the $metadata definition.

    If you define WP_DEBUG as true in wp-config.php, these sort of blunders will get flagged and PHP will output an appropriate warning. It’s great for testing code, but don’t leave it as true on production sites, it’s a slight security risk.

Viewing 1 replies (of 1 total)
  • The topic ‘How to fix Schema Error on WordPress’ is closed to new replies.