Skip to content

Instantly share code, notes, and snippets.

@tiborp
Forked from jdevalk/archive-speaking_event.php
Created June 20, 2013 11:26

Revisions

  1. Joost de Valk revised this gist May 29, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions genesis-schema-helper-functions.php
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,8 @@

    // Remove the schema markup from an element
    function yoast_schema_empty( $attr ) {
    $attr['itemtype'] = '';
    $attr['itemtype'] = '';
    $attr['itemtype'] = '';
    $attr['itemprop'] = '';
    $attr['itemscope'] = '';
    return $attr;
    }
  2. Joost de Valk revised this gist May 28, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion genesis-schema-helper-functions.php
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,7 @@ function yoast_author_schema( $output ) {
    return str_replace( 'rel="author"', 'itemprop="author"', $output );
    }

    // Add the url itemprop to the URL of the event
    // Add the url itemprop to the URL of the entry
    function yoast_title_link_schema( $output ) {
    return str_replace( 'rel="bookmark"', 'rel="bookmark" itemprop="url"', $output );
    }
  3. Joost de Valk revised this gist May 28, 2013. 2 changed files with 6 additions and 0 deletions.
    1 change: 1 addition & 0 deletions archive-speaking_event.php
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@
    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.
    5 changes: 5 additions & 0 deletions genesis-schema-helper-functions.php
    Original file line number Diff line number Diff line change
    @@ -50,3 +50,8 @@ function yoast_itemprop_name( $attr ) {
    function yoast_author_schema( $output ) {
    return str_replace( 'rel="author"', 'itemprop="author"', $output );
    }

    // Add the url itemprop to the URL of the event
    function yoast_title_link_schema( $output ) {
    return str_replace( 'rel="bookmark"', 'rel="bookmark" itemprop="url"', $output );
    }
  4. Joost de Valk revised this gist May 28, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions archive-speaking_event.php
    Original file line number Diff line number Diff line change
    @@ -13,9 +13,9 @@
    */
    function yoast_speaking_post_info( $info ) {
    global $post;
    $date = esc_html( get_post_meta( $post->ID, 'date', true ) );
    $date = esc_html( get_post_meta( $post->ID, 'date', true ) );
    $startdate = '<meta itemprop="startDate" content="' . date('c', strtotime( $date ) ).'">' . $date;
    $enddate = esc_html( get_post_meta( $post->ID, 'enddate', true ) );
    $enddate = esc_html( get_post_meta( $post->ID, 'enddate', true ) );

    if ( $enddate && $enddate != $date )
    $startdate .= ' - <meta itemprop="endDate" content="' . date( 'c', strtotime( $enddate ) ).'">' . $enddate;
  5. Joost de Valk revised this gist May 28, 2013. 1 changed file with 30 additions and 0 deletions.
    30 changes: 30 additions & 0 deletions archive-speaking_event.php
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,34 @@
    add_filter( 'genesis_attr_entry-title', 'yoast_itemprop_name', 20 );
    add_filter( 'genesis_attr_entry-content', 'yoast_itemprop_description', 20 );

    /**
    * We'll use the post info output to add more meta data about the event.
    *
    * @param string $info
    * @return string
    */
    function yoast_speaking_post_info( $info ) {
    global $post;
    $date = esc_html( get_post_meta( $post->ID, 'date', true ) );
    $startdate = '<meta itemprop="startDate" content="' . date('c', strtotime( $date ) ).'">' . $date;
    $enddate = esc_html( get_post_meta( $post->ID, 'enddate', true ) );

    if ( $enddate && $enddate != $date )
    $startdate .= ' - <meta itemprop="endDate" content="' . date( 'c', strtotime( $enddate ) ).'">' . $enddate;

    $location = esc_html( get_post_meta( $post->ID, 'location', true ) );
    if ( $location )
    $location = 'at <span itemprop="location" itemscope itemtype="http://schema.org/Place"><span itemprop="name">' . $location . '</span>, ';

    $city = esc_html( get_post_meta( $post->ID, 'city', true ) );
    $country = esc_html( get_post_meta( $post->ID, 'country', true ) );
    if ( $location )
    $location .= '<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress"><span itemprop="addressLocality">' . $city . '</span>, <span itemprop="addressCountry">' . $country . '</span></span>';
    else
    $location = '<span itemprop="location" itemscope itemtype="http://schema.org/Place"><span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress"><span itemprop="addressLocality">' . $city . '</span>, <span itemprop="addressCountry">' . $country . '</span></span></span>';

    return "$startdate $location";
    }
    add_filter( 'genesis_post_info' , 'yoast_speaking_post_info' );

    genesis();
  6. Joost de Valk created this gist May 28, 2013.
    8 changes: 8 additions & 0 deletions archive-speaking_event.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <?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 );

    genesis();
    52 changes: 52 additions & 0 deletions genesis-schema-helper-functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    <?php

    // Remove the schema markup from an element
    function yoast_schema_empty( $attr ) {
    $attr['itemtype'] = '';
    $attr['itemtype'] = '';
    $attr['itemscope'] = '';
    return $attr;
    }

    // Change the schema type of an element to Product
    function yoast_schema_product( $attr ) {
    $attr['itemtype'] = 'http://schema.org/Product';
    $attr['itemprop'] = '';
    $attr['itemscope'] = 'itemscope';
    return $attr;
    }

    // Change the schema type of an element to Event
    function yoast_schema_event( $attr ) {
    $attr['itemtype'] = 'http://schema.org/Event';
    $attr['itemprop'] = '';
    $attr['itemscope'] = 'itemscope';
    return $attr;
    }

    // Change the schema type of an element to Review
    // Make sure the itemprop is set to review so this can be used in conjunction with Event or Product
    function yoast_schema_review( $attr ) {
    $attr['itemtype'] = 'http://schema.org/Review';
    $attr['itemprop'] = 'review';
    $attr['itemscope'] = 'itemscope';
    return $attr;
    }

    // Set the itemprop of an element to description
    function yoast_itemprop_description( $attr ) {
    $attr['itemprop'] = 'description';
    return $attr;
    }

    // Set the itemprop of an element to name
    function yoast_itemprop_name( $attr ) {
    $attr['itemprop'] = 'name';
    return $attr;
    }

    // Remove the rel="author" and change it to itemprop="author" as the Structured Data Testing Tool doesn't understand
    // rel="author" in relation to Schema, even though it should according to the spec.
    function yoast_author_schema( $output ) {
    return str_replace( 'rel="author"', 'itemprop="author"', $output );
    }