Skip to content

Commit

Permalink
Merge pull request #20 from kimcoleman/dev
Browse files Browse the repository at this point in the history
Moving schema itemReviewed inline
  • Loading branch information
kimcoleman authored Jan 15, 2025
2 parents 273ccaf + 8b6391a commit b6812e0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
38 changes: 0 additions & 38 deletions includes/hooks.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
<?php
// Add review schema to site <head>.
function pmpro_testimonial_wp_head() {
global $post;

// Check if the post content contains the specific shortcodes
if ( $post && ( has_shortcode( $post->post_content, 'pmpro_testimonials_display' ) || has_shortcode( $post->post_content, 'pmpro_testimonials_display_custom' ) ) ) {
// Get site title and URL
$site_title = get_bloginfo('name');
$site_url = get_bloginfo('url');
$schema_type = get_option( 'pmpro_testimonials_schema_type', 'Service' );
$schema_name = sprintf(
/* translators: %s: Site title */
__( '%s Membership', 'pmpro-testimonials' ),
get_bloginfo( 'name' )
);
$schema_description = get_option( 'pmpro_testimonials_schema_description' );
if ( empty( $schema_description ) ) {
$schema_description = __( 'Access exclusive content and benefits with our memberships.', 'pmpro-testimonials' );
}

// Output the structured data
echo '<script type="application/ld+json">
{
"@context": "https://schema.org/",
"@type": "' . esc_html( $schema_type ) . '",
"name": "' . esc_html( $schema_name ) . '",
"description": "' . esc_html( $schema_description ) . '",
"provider": {
"@type": "Organization",
"name": "' . esc_html( $site_title ) . '",
"url": "' . esc_url( $site_url ) . '"
}
}
</script>';
}
}
add_action( 'wp_head', 'pmpro_testimonial_wp_head' );

// Used for the featured image block.
function pmpro_testimonial_featured_image_fallback( $html, $post_id, $post_thumbnail_id, $size, $attr ) {

Expand Down
17 changes: 17 additions & 0 deletions includes/shortcodes/display.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ function pmpro_testimonials_display_custom( $atts, $content = '' ) {
'pmpro_testimonials_display_custom'
);

// Get data for the itemReviewed schema.
$site_title = get_bloginfo('name');
$schema_type = 'https://schema.org/' . get_option( 'pmpro_testimonials_schema_type', 'Service' );
$schema_name = sprintf(
/* translators: %s: Site title */
__( '%s Membership', 'pmpro-testimonials' ),
get_bloginfo( 'name' )
);
$schema_description = get_option( 'pmpro_testimonials_schema_description' );
if ( empty( $schema_description ) ) {
$schema_description = __( 'Access exclusive content and benefits with our memberships.', 'pmpro-testimonials' );
}

$html = '';
$display = new PMPro_Testimonial_Display( $atts );
$testimonials = $display->get_testimonials();
Expand All @@ -55,6 +68,10 @@ function pmpro_testimonials_display_custom( $atts, $content = '' ) {
$GLOBALS['current_pmpro_testimonial'] = $testimonial;
$html .= do_shortcode( $content );
unset( $GLOBALS['current_pmpro_testimonial'] );
$html .= '<div itemprop="itemReviewed" itemscope itemtype="' . esc_url( $schema_type ) . '">';
$html .= '<meta itemprop="name" content="' . esc_attr( $schema_name ) . '" />';
$html .= '<meta itemprop="description" content="' . esc_attr( $schema_description ) . '" />';
$html .= '</div>';
$html .= '</div>';
}
$html .= '</div>';
Expand Down
18 changes: 18 additions & 0 deletions layouts/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,23 @@
endif;
?>

<?php
// Get data for the itemReviewed schema.
$site_title = get_bloginfo('name');
$schema_type = 'https://schema.org/' . get_option( 'pmpro_testimonials_schema_type', 'Service' );
$schema_name = sprintf(
/* translators: %s: Site title */
__( '%s Membership', 'pmpro-testimonials' ),
get_bloginfo( 'name' )
);
$schema_description = get_option( 'pmpro_testimonials_schema_description' );
if ( empty( $schema_description ) ) {
$schema_description = __( 'Access exclusive content and benefits with our memberships.', 'pmpro-testimonials' );
}
?>
<div itemprop="itemReviewed" itemscope itemtype="<?php echo esc_url( $schema_type ); ?>">
<meta itemprop="name" content="<?php echo esc_attr( $schema_name ); ?>" />
<meta itemprop="description" content="<?php echo esc_attr( $schema_description ); ?>" />
</div>
</div> <!-- .pmpro_card_content -->
</div> <!-- .pmpro_card -->

0 comments on commit b6812e0

Please sign in to comment.