Update and fix SEO meta and schemas

This commit is contained in:
Tetrakern 2023-09-04 23:14:44 +02:00
parent 0a0dac0874
commit ea89b56dc4
10 changed files with 107 additions and 143 deletions

View File

@ -566,6 +566,14 @@ if ( get_option( 'fictioneer_enable_storygraph_api' ) ) {
require_once __DIR__ . '/includes/functions/_search.php'; require_once __DIR__ . '/includes/functions/_search.php';
/**
* Generate SEO schema graphs.
*/
if ( get_option( 'fictioneer_enable_seo' ) && ! fictioneer_seo_plugin_active() ) {
require_once __DIR__ . '/includes/functions/_schemas.php';
}
// ============================================================================= // =============================================================================
// ADMIN ONLY // ADMIN ONLY
// ============================================================================= // =============================================================================
@ -628,14 +636,6 @@ if ( ! is_admin() ) {
*/ */
require_once __DIR__ . '/includes/functions/hooks/_mobile_menu_hooks.php'; require_once __DIR__ . '/includes/functions/hooks/_mobile_menu_hooks.php';
/**
* Generate SEO schema graphs.
*/
if ( get_option( 'fictioneer_enable_seo' ) && ! fictioneer_seo_plugin_active() ) {
require_once __DIR__ . '/includes/functions/_schemas.php';
}
} }
?> ?>

View File

@ -49,16 +49,16 @@ if ( ! function_exists( 'fictioneer_seo_fields' ) ) {
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param object $post The post object. * @param object $post The post object.
*/ */
function fictioneer_seo_fields( $post ) { function fictioneer_seo_fields( $post ) {
// Title // Title
$seo_title = get_post_meta( $post->ID, 'fictioneer_seo_title', true ) ?? '{{title}} {{site}}'; $seo_title = get_post_meta( $post->ID, 'fictioneer_seo_title', true ) ?: '';
$seo_title_placeholder = fictioneer_get_safe_title( $post->ID ) . ' ' . FICTIONEER_SITE_NAME; $seo_title_placeholder = fictioneer_get_safe_title( $post->ID );
// Description (truncated if necessary) // Description (truncated if necessary)
$seo_description = get_post_meta( $post->ID, 'fictioneer_seo_description', true ) ?? '{{excerpt}}'; $seo_description = get_post_meta( $post->ID, 'fictioneer_seo_description', true ) ?: '';
$seo_description_placeholder = wp_strip_all_tags( get_the_excerpt( $post ), true ); $seo_description_placeholder = wp_strip_all_tags( get_the_excerpt( $post ), true );
$seo_description_placeholder = mb_strimwidth( $seo_description_placeholder, 0, 155, '…' ); $seo_description_placeholder = mb_strimwidth( $seo_description_placeholder, 0, 155, '…' );
@ -74,7 +74,7 @@ if ( ! function_exists( 'fictioneer_seo_fields' ) ) {
} }
// ... if not found, look for parent thumbnail... // ... if not found, look for parent thumbnail...
if ( ! $seo_og_image_display && $post->post_type == 'fcn_chapter' ) { if ( ! $seo_og_image_display && $post->post_type === 'fcn_chapter' ) {
$story_id = fictioneer_get_field( 'fictioneer_chapter_story', $post->ID ); $story_id = fictioneer_get_field( 'fictioneer_chapter_story', $post->ID );
if ( $story_id && has_post_thumbnail( $story_id ) ) { if ( $story_id && has_post_thumbnail( $story_id ) ) {
@ -109,7 +109,7 @@ if ( ! function_exists( 'fictioneer_seo_fields' ) ) {
<span><?php _e( 'Title', 'fictioneer' ); ?></span> <span><?php _e( 'Title', 'fictioneer' ); ?></span>
<span id="fictioneer-seo-title-chars" class="counter"></span> <span id="fictioneer-seo-title-chars" class="counter"></span>
</label> </label>
<input id="fictioneer-seo-title" type="text" data-lpignore="true" name="fictioneer_seo_title" value="<?php echo esc_attr( $seo_title ); ?>" placeholder="<?php echo esc_attr( $seo_title_placeholder ); ?>"> <input id="fictioneer-seo-title" type="text" name="fictioneer_seo_title" value="<?php echo esc_attr( $seo_title ); ?>" placeholder="<?php echo esc_attr( $seo_title_placeholder ); ?>">
</div> </div>
<div class="fictioneer-metabox__row"> <div class="fictioneer-metabox__row">
@ -172,17 +172,17 @@ function fictioneer_save_seo_metabox( $post_id ) {
// Save image // Save image
if ( isset( $_POST['fictioneer_seo_og_image'] ) ) { if ( isset( $_POST['fictioneer_seo_og_image'] ) ) {
update_post_meta( $post_id, 'fictioneer_seo_og_image', $_POST['fictioneer_seo_og_image'] ); update_post_meta( $post_id, 'fictioneer_seo_og_image', absint( $_POST['fictioneer_seo_og_image'] ) );
} }
// Save title // Save title
if ( isset( $_POST['fictioneer_seo_title'] ) ) { if ( isset( $_POST['fictioneer_seo_title'] ) ) {
update_post_meta( $post_id, 'fictioneer_seo_title', $_POST['fictioneer_seo_title'] ); update_post_meta( $post_id, 'fictioneer_seo_title', sanitize_text_field( $_POST['fictioneer_seo_title'] ) );
} }
// Save description // Save description
if ( isset( $_POST['fictioneer_seo_description'] ) ) { if ( isset( $_POST['fictioneer_seo_description'] ) ) {
update_post_meta( $post_id, 'fictioneer_seo_description', $_POST['fictioneer_seo_description'] ); update_post_meta( $post_id, 'fictioneer_seo_description', sanitize_text_field( $_POST['fictioneer_seo_description'] ) );
} }
// Clear caches // Clear caches
@ -209,8 +209,8 @@ if ( ! function_exists( 'fictioneer_get_seo_title' ) ) {
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id Optional. The post ID. * @param int $post_id Optional. The post ID.
* @param array $args Optional. Array of arguments. * @param array $args Optional. Array of arguments.
* *
* @return string The SEO title. * @return string The SEO title.
*/ */
@ -218,18 +218,15 @@ if ( ! function_exists( 'fictioneer_get_seo_title' ) ) {
function fictioneer_get_seo_title( $post_id = null, $args = [] ) { function fictioneer_get_seo_title( $post_id = null, $args = [] ) {
// Setup // Setup
$post_id = $post_id ? $post_id : get_queried_object_id(); $post_id = $post_id ? $post_id : get_queried_object_id();
$page = get_query_var( 'paged', 0 ); // Only default pagination is considered $skip_cache = $args['skip_cache'] ?? false;
$page_note = $page > 1 ? sprintf( __( ' Page %s', 'fictioneer' ), $page ) : ''; $default = ! empty( trim( $args['default'] ?? '' ) ) ? $args['default'] : false;
$site_name = FICTIONEER_SITE_NAME;
$skip_cache = isset( $args['skip_cache'] ) && $args['skip_cache'];
$default = isset( $args['default'] ) && ! empty( $args['default'] ) ? $args['default'] : false;
// Search? // Search?
if ( is_search() ) { if ( is_search() ) {
return esc_html( return esc_html(
sprintf( sprintf(
_x( 'Search %s', 'Search Site Name.', 'fictioneer' ), _x( 'Search Results', 'SEO search results title.', 'fictioneer' ),
$site_name FICTIONEER_SITE_NAME
) )
); );
} }
@ -240,9 +237,14 @@ if ( ! function_exists( 'fictioneer_get_seo_title' ) ) {
$author = get_userdata( $author_id ); $author = get_userdata( $author_id );
if ( $author ) { if ( $author ) {
return $author->display_name; return esc_html(
sprintf(
_x( 'Author: %s', 'SEO author page title.', 'fictioneer' ),
$author->display_name
)
);
} else { } else {
return _x( 'Author', 'Fallback SEO title for author pages.', 'fictioneer' ); return esc_html( _x( 'Author', 'SEO fallback title for author pages.', 'fictioneer' ) );
} }
} }
@ -252,10 +254,8 @@ if ( ! function_exists( 'fictioneer_get_seo_title' ) ) {
if ( is_category() ) { if ( is_category() ) {
return esc_html( return esc_html(
sprintf( sprintf(
_x( 'Category: %1$s%2$s %3$s', 'Category: Category[ Page n] Site Name. The page is optional.', 'fictioneer' ), _x( 'Category: %s', 'SEO post category title.', 'fictioneer' ),
single_cat_title( '', false ), single_cat_title( '', false )
$page_note,
$site_name
) )
); );
} }
@ -264,10 +264,8 @@ if ( ! function_exists( 'fictioneer_get_seo_title' ) ) {
if ( is_tag() ) { if ( is_tag() ) {
return esc_html( return esc_html(
sprintf( sprintf(
_x( 'Tag: %1$s%2$s %3$s', 'Tag: Tag[ Page n] Site Name. The page is optional.', 'fictioneer' ), _x( 'Tag: %s', 'SEO post tag title.', 'fictioneer' ),
single_tag_title( '', false ), single_tag_title( '', false )
$page_note,
$site_name
) )
); );
} }
@ -276,10 +274,8 @@ if ( ! function_exists( 'fictioneer_get_seo_title' ) ) {
if ( is_tax( 'fcn_character' ) ) { if ( is_tax( 'fcn_character' ) ) {
return esc_html( return esc_html(
sprintf( sprintf(
_x( 'Character: %1$s%2$s %3$s', 'Character: Character[ Page n] Site Name. The page is optional.', 'fictioneer' ), _x( 'Character: %s', 'SEO character taxonomy title.', 'fictioneer' ),
single_tag_title( '', false ), single_tag_title( '', false )
$page_note,
$site_name
) )
); );
} }
@ -288,10 +284,8 @@ if ( ! function_exists( 'fictioneer_get_seo_title' ) ) {
if ( is_tax( 'fcn_fandom' ) ) { if ( is_tax( 'fcn_fandom' ) ) {
return esc_html( return esc_html(
sprintf( sprintf(
_x( 'Fandom: %1$s%2$s %3$s', 'Fandom: Fandom[ Page n] Site Name. The page is optional.', 'fictioneer' ), _x( 'Fandom: %s', 'SEO fandom taxonomy title.', 'fictioneer' ),
single_tag_title( '', false ), single_tag_title( '', false )
$page_note,
$site_name
) )
); );
} }
@ -300,16 +294,14 @@ if ( ! function_exists( 'fictioneer_get_seo_title' ) ) {
if ( is_tax( 'fcn_genre' ) ) { if ( is_tax( 'fcn_genre' ) ) {
return esc_html( return esc_html(
sprintf( sprintf(
_x( 'Genre: %1$s%2$s %3$s', 'Genre: Genre[ Page n] Site Name. The page is optional.', 'fictioneer' ), _x( 'Genre: %s', 'SEO genre taxonomy title.', 'fictioneer' ),
single_tag_title( '', false ), single_tag_title( '', false )
$page_note,
$site_name
) )
); );
} }
// Generic archive? // Generic archive?
return esc_html( sprintf( __( 'Archive %1$s', 'fictioneer' ), $site_name ) ); return esc_html( _x( 'Archive', 'SEO fallback archive title.', 'fictioneer' ) );
} }
// Cached title? // Cached title?
@ -322,35 +314,32 @@ if ( ! function_exists( 'fictioneer_get_seo_title' ) ) {
// Start building... // Start building...
$seo_title = get_post_meta( $post_id, 'fictioneer_seo_title', true ); $seo_title = get_post_meta( $post_id, 'fictioneer_seo_title', true );
$seo_title = empty( $seo_title ) ? false : $seo_title; $seo_title = empty( $seo_title ) ? false : $seo_title;
$title = fictioneer_get_safe_title( $post_id );
$default = empty( $default ) ? $title : $default;
// Frontpage case... // Special Case: Frontpage
if ( is_front_page() && $seo_title == '{{title}} {{site}}' ) { if ( is_front_page() ) {
$seo_title = $site_name; $default = empty( $default ) ? FICTIONEER_SITE_NAME : $default;
}
// Placeholder: {{title}}
if ( str_contains( $seo_title, '{{title}}' ) ) {
$seo_title = str_replace( '{{title}}', $title, $seo_title );
}
// Placeholder: {{site}}
if ( str_contains( $seo_title, '{{site}}' ) ) {
$seo_title = str_replace( '{{site}}', FICTIONEER_SITE_NAME ?? '', $seo_title );
} }
// Defaults... // Defaults...
if ( $default && ( ! $seo_title || $seo_title == '{{title}} {{site}}' ) ) { if ( ! empty( $default ) && empty( $seo_title ) ) {
$seo_title = $default; $seo_title = $default;
} }
// Replace {{title}} placeholder...
if ( str_contains( $seo_title, '{{title}}' ) ) {
$seo_title = str_replace( '{{title}}', fictioneer_get_safe_title( $post_id ), $seo_title );
}
// Replace {{site}} placeholder...
if ( str_contains( $seo_title, '{{site}}' ) ) {
$seo_title = str_replace( '{{site}}', $site_name, $seo_title );
}
// Catch empty // Catch empty
if ( empty( $seo_title ) ) { if ( empty( $seo_title ) ) {
$seo_title = sprintf( $seo_title = FICTIONEER_SITE_NAME;
_x( '%1$s%2$s %3$s', 'Post Title[ Page n] Site Name. The page is optional.', 'fictioneer' ),
get_the_title( $post_id ),
$page_note,
$site_name
);
} }
// Finalize // Finalize
@ -403,7 +392,7 @@ if ( ! function_exists( 'fictioneer_get_seo_description' ) ) {
$author = get_userdata( $author_id ); $author = get_userdata( $author_id );
if ( $author && ! empty( $author->user_description ) ) { if ( $author && ! empty( $author->user_description ) ) {
return $author->user_description; return esc_html( $author->user_description );
} else { } else {
return esc_html( return esc_html(
sprintf( sprintf(
@ -480,6 +469,7 @@ if ( ! function_exists( 'fictioneer_get_seo_description' ) ) {
// Start building... // Start building...
$seo_description = get_post_meta( $post_id, 'fictioneer_seo_description', true ); $seo_description = get_post_meta( $post_id, 'fictioneer_seo_description', true );
$seo_description = empty( $seo_description ) ? false : $seo_description; $seo_description = empty( $seo_description ) ? false : $seo_description;
$title = fictioneer_get_safe_title( $post_id );
$excerpt = wp_strip_all_tags( get_the_excerpt( $post_id ), true ); $excerpt = wp_strip_all_tags( get_the_excerpt( $post_id ), true );
$excerpt = mb_strimwidth( $excerpt, 0, 155, '…' ); $excerpt = mb_strimwidth( $excerpt, 0, 155, '…' );
$default = empty( $default ) ? $excerpt : $default; $default = empty( $default ) ? $excerpt : $default;
@ -497,6 +487,16 @@ if ( ! function_exists( 'fictioneer_get_seo_description' ) ) {
$seo_description = str_replace( '{{excerpt}}', $excerpt ?? '', $seo_description ); $seo_description = str_replace( '{{excerpt}}', $excerpt ?? '', $seo_description );
} }
// Placeholder: {{title}}
if ( str_contains( $seo_description, '{{title}}' ) ) {
$seo_description = str_replace( '{{title}}', $title, $seo_description );
}
// Placeholder: {{site}}
if ( str_contains( $seo_description, '{{site}}' ) ) {
$seo_description = str_replace( '{{site}}', FICTIONEER_SITE_NAME ?? '', $seo_description );
}
// Defaults... // Defaults...
if ( ! empty( $default ) && empty( $seo_description ) ) { if ( ! empty( $default ) && empty( $seo_description ) ) {
$seo_description = $default; $seo_description = $default;
@ -504,7 +504,7 @@ if ( ! function_exists( 'fictioneer_get_seo_description' ) ) {
// Catch empty // Catch empty
if ( empty( $seo_description ) ) { if ( empty( $seo_description ) ) {
$seo_description = empty( $default ) ? FICTIONEER_SITE_DESCRIPTION : $default; $seo_description = FICTIONEER_SITE_DESCRIPTION;
} }
// Finalize // Finalize

View File

@ -12,8 +12,8 @@
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the saved post. * @param int $post_id The ID of the saved post.
* @param WP_Post $post The saved post object. * @param WP_Post $post The saved post object.
*/ */
function fictioneer_refresh_chapter_schema( $post_id, $post ) { function fictioneer_refresh_chapter_schema( $post_id, $post ) {
@ -63,14 +63,7 @@ if ( ! function_exists( 'fictioneer_build_chapter_schema' ) ) {
$image_data = fictioneer_get_schema_primary_image( $post_id ); $image_data = fictioneer_get_schema_primary_image( $post_id );
$word_count = intval( get_post_meta( $post_id, '_word_count', true ) ); $word_count = intval( get_post_meta( $post_id, '_word_count', true ) );
$page_description = fictioneer_get_seo_description( $post_id ); $page_description = fictioneer_get_seo_description( $post_id );
$page_title = fictioneer_get_seo_title( $post_id, array( 'skip_cache' => true ) );
$page_title = fictioneer_get_seo_title(
$post_id,
array(
'default' => fictioneer_get_safe_title( $post_id ) . ' &ndash; ' . FICTIONEER_SITE_NAME,
'skip_cache' => true
)
);
// Website node // Website node
$schema['@graph'][] = fictioneer_get_schema_node_website(); $schema['@graph'][] = fictioneer_get_schema_node_website();

View File

@ -12,8 +12,8 @@
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the saved post. * @param int $post_id The ID of the saved post.
* @param WP_Post $post The saved post object. * @param WP_Post $post The saved post object.
*/ */
function fictioneer_refresh_chapters_schema( $post_id, $post ) { function fictioneer_refresh_chapters_schema( $post_id, $post ) {
@ -59,7 +59,7 @@ if ( ! function_exists( 'fictioneer_build_chapters_schema' ) ) {
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the page the schema is for. * @param int $post_id The ID of the page the schema is for.
* *
* @return string The encoded JSON or an empty string. * @return string The encoded JSON or an empty string.
*/ */
@ -94,17 +94,14 @@ if ( ! function_exists( 'fictioneer_build_chapters_schema' ) ) {
$page_description = fictioneer_get_seo_description( $post_id, array( $page_description = fictioneer_get_seo_description( $post_id, array(
'default' => sprintf( 'default' => sprintf(
__( 'All chapters hosted on %s.', 'fictioneer' ), __( 'All chapters on %s.', 'fictioneer' ),
FICTIONEER_SITE_NAME FICTIONEER_SITE_NAME
), ),
'skip_cache' => true 'skip_cache' => true
)); ));
$page_title = fictioneer_get_seo_title( $post_id, array( $page_title = fictioneer_get_seo_title( $post_id, array(
'default' => sprintf( 'default' => _x( 'Chapters', 'SEO fallback title for Chapters template.', 'fictioneer' ),
__( 'Chapters %s.', 'fictioneer' ),
FICTIONEER_SITE_NAME
),
'skip_cache' => true 'skip_cache' => true
)); ));

View File

@ -12,8 +12,8 @@
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the saved post. * @param int $post_id The ID of the saved post.
* @param WP_Post $post The saved post object. * @param WP_Post $post The saved post object.
*/ */
function fictioneer_refresh_collections_schema( $post_id, $post ) { function fictioneer_refresh_collections_schema( $post_id, $post ) {
@ -59,7 +59,7 @@ if ( ! function_exists( 'fictioneer_build_collections_schema' ) ) {
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the page the schema is for. * @param int $post_id The ID of the page the schema is for.
* *
* @return string The encoded JSON or an empty string. * @return string The encoded JSON or an empty string.
*/ */
@ -90,17 +90,14 @@ if ( ! function_exists( 'fictioneer_build_collections_schema' ) ) {
$page_description = fictioneer_get_seo_description( $post_id, array( $page_description = fictioneer_get_seo_description( $post_id, array(
'default' => sprintf( 'default' => sprintf(
__( 'Collections on %s.', 'fictioneer' ), __( 'All collections on %s.', 'fictioneer' ),
FICTIONEER_SITE_NAME FICTIONEER_SITE_NAME
), ),
'skip_cache' => true 'skip_cache' => true
)); ));
$page_title = fictioneer_get_seo_title( $post_id, array( $page_title = fictioneer_get_seo_title( $post_id, array(
'default' => sprintf( 'default' => _x( 'Collections', 'SEO fallback title for Collections template.', 'fictioneer' ),
__( 'Collections %s.', 'fictioneer' ),
FICTIONEER_SITE_NAME
),
'skip_cache' => true 'skip_cache' => true
)); ));

View File

@ -12,8 +12,8 @@
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the saved post. * @param int $post_id The ID of the saved post.
* @param WP_Post $post The saved post object. * @param WP_Post $post The saved post object.
*/ */
function fictioneer_refresh_post_schema( $post_id, $post ) { function fictioneer_refresh_post_schema( $post_id, $post ) {
@ -42,7 +42,7 @@ if ( ! function_exists( 'fictioneer_build_post_schema' ) ) {
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the recommendation the schema is for. * @param int $post_id The ID of the recommendation the schema is for.
* *
* @return string The encoded JSON or an empty string. * @return string The encoded JSON or an empty string.
*/ */
@ -57,11 +57,7 @@ if ( ! function_exists( 'fictioneer_build_post_schema' ) ) {
$schema = fictioneer_get_schema_node_root(); $schema = fictioneer_get_schema_node_root();
$image_data = fictioneer_get_schema_primary_image( $post_id ); $image_data = fictioneer_get_schema_primary_image( $post_id );
$page_description = fictioneer_get_seo_description( $post_id ); $page_description = fictioneer_get_seo_description( $post_id );
$page_title = fictioneer_get_seo_title( $post_id, array( 'skip_cache' => true ) );
$page_title = fictioneer_get_seo_title( $post_id, array(
'default' => fictioneer_get_safe_title( $post_id ) . ' &ndash; ' . FICTIONEER_SITE_NAME,
'skip_cache' => true
));
// Website node // Website node
$schema['@graph'][] = fictioneer_get_schema_node_website(); $schema['@graph'][] = fictioneer_get_schema_node_website();

View File

@ -12,8 +12,8 @@
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the saved post. * @param int $post_id The ID of the saved post.
* @param WP_Post $post The saved post object. * @param WP_Post $post The saved post object.
*/ */
function fictioneer_refresh_recommendation_schema( $post_id, $post ) { function fictioneer_refresh_recommendation_schema( $post_id, $post ) {
@ -42,7 +42,7 @@ if ( ! function_exists( 'fictioneer_build_recommendation_schema' ) ) {
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the recommendation the schema is for. * @param int $post_id The ID of the recommendation the schema is for.
* *
* @return string The encoded JSON or an empty string. * @return string The encoded JSON or an empty string.
*/ */
@ -56,6 +56,7 @@ if ( ! function_exists( 'fictioneer_build_recommendation_schema' ) ) {
// Setup // Setup
$schema = fictioneer_get_schema_node_root(); $schema = fictioneer_get_schema_node_root();
$image_data = fictioneer_get_schema_primary_image( $post_id ); $image_data = fictioneer_get_schema_primary_image( $post_id );
$page_title = fictioneer_get_seo_title( $post_id, array( 'skip_cache' => true ) );
$page_description = fictioneer_get_seo_description( $page_description = fictioneer_get_seo_description(
$post_id, $post_id,
@ -65,14 +66,6 @@ if ( ! function_exists( 'fictioneer_build_recommendation_schema' ) ) {
) )
); );
$page_title = fictioneer_get_seo_title(
$post_id,
array(
'default' => fictioneer_get_safe_title( $post_id ) . ' &ndash; ' . FICTIONEER_SITE_NAME,
'skip_cache' => true
)
);
// Website node // Website node
$schema['@graph'][] = fictioneer_get_schema_node_website(); $schema['@graph'][] = fictioneer_get_schema_node_website();

View File

@ -12,8 +12,8 @@
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the saved post. * @param int $post_id The ID of the saved post.
* @param WP_Post $post The saved post object. * @param WP_Post $post The saved post object.
*/ */
function fictioneer_refresh_recommendations_schema( $post_id, $post ) { function fictioneer_refresh_recommendations_schema( $post_id, $post ) {
@ -59,7 +59,7 @@ if ( ! function_exists( 'fictioneer_build_recommendations_schema' ) ) {
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the page the schema is for. * @param int $post_id The ID of the page the schema is for.
* *
* @return string The encoded JSON or an empty string. * @return string The encoded JSON or an empty string.
*/ */
@ -90,17 +90,14 @@ if ( ! function_exists( 'fictioneer_build_recommendations_schema' ) ) {
$page_description = fictioneer_get_seo_description( $post_id, array( $page_description = fictioneer_get_seo_description( $post_id, array(
'default' => sprintf( 'default' => sprintf(
__( 'Recommendations on %s.', 'fictioneer' ), __( 'All recommendations on %s.', 'fictioneer' ),
FICTIONEER_SITE_NAME FICTIONEER_SITE_NAME
), ),
'skip_cache' => true 'skip_cache' => true
)); ));
$page_title = fictioneer_get_seo_title( $post_id, array( $page_title = fictioneer_get_seo_title( $post_id, array(
'default' => sprintf( 'default' => _x( 'Recommendations', 'SEO fallback title for Recommendations template.', 'fictioneer' ),
__( 'Recommendations %s.', 'fictioneer' ),
FICTIONEER_SITE_NAME
),
'skip_cache' => true 'skip_cache' => true
)); ));

View File

@ -12,8 +12,8 @@
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the saved post. * @param int $post_id The ID of the saved post.
* @param WP_Post $post The saved post object. * @param WP_Post $post The saved post object.
*/ */
function fictioneer_refresh_stories_schema( $post_id, $post ) { function fictioneer_refresh_stories_schema( $post_id, $post ) {
@ -59,7 +59,7 @@ if ( ! function_exists( 'fictioneer_build_stories_schema' ) ) {
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the page the schema is for. * @param int $post_id The ID of the page the schema is for.
* *
* @return string The encoded JSON or an empty string. * @return string The encoded JSON or an empty string.
*/ */
@ -90,17 +90,14 @@ if ( ! function_exists( 'fictioneer_build_stories_schema' ) ) {
$page_description = fictioneer_get_seo_description( $post_id, array( $page_description = fictioneer_get_seo_description( $post_id, array(
'default' => sprintf( 'default' => sprintf(
__( 'All stories hosted on %s.', 'fictioneer' ), __( 'All stories on %s.', 'fictioneer' ),
FICTIONEER_SITE_NAME FICTIONEER_SITE_NAME
), ),
'skip_cache' => true 'skip_cache' => true
)); ));
$page_title = fictioneer_get_seo_title( $post_id, array( $page_title = fictioneer_get_seo_title( $post_id, array(
'default' => sprintf( 'default' => _x( 'Stories', 'SEO fallback title for Stories template.', 'fictioneer' ),
__( 'Stories %s.', 'fictioneer' ),
FICTIONEER_SITE_NAME
),
'skip_cache' => true 'skip_cache' => true
)); ));

View File

@ -12,8 +12,8 @@
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the saved post. * @param int $post_id The ID of the saved post.
* @param WP_Post $post The saved post object. * @param WP_Post $post The saved post object.
*/ */
function fictioneer_refresh_story_schema( $post_id, $post ) { function fictioneer_refresh_story_schema( $post_id, $post ) {
@ -52,7 +52,7 @@ if ( ! function_exists( 'fictioneer_build_story_schema' ) ) {
* *
* @since Fictioneer 4.0 * @since Fictioneer 4.0
* *
* @param int $post_id The ID of the story the schema is for. * @param int $post_id The ID of the story the schema is for.
* *
* @return string The encoded JSON or an empty string. * @return string The encoded JSON or an empty string.
*/ */
@ -70,8 +70,10 @@ if ( ! function_exists( 'fictioneer_build_story_schema' ) ) {
$chapters = fictioneer_get_field( 'fictioneer_story_chapters', $post_id ); $chapters = fictioneer_get_field( 'fictioneer_story_chapters', $post_id );
$chapter_count = 0; $chapter_count = 0;
$chapter_list = []; $chapter_list = [];
$page_title = fictioneer_get_seo_title( $post_id, array( 'skip_cache' => true ) );
$page_description = fictioneer_first_paragraph_as_excerpt( fictioneer_get_content_field( 'fictioneer_story_short_description', $post_id ) ); $page_description = fictioneer_first_paragraph_as_excerpt( fictioneer_get_content_field( 'fictioneer_story_short_description', $post_id ) );
$page_description = fictioneer_get_seo_description( $page_description = fictioneer_get_seo_description(
$post_id, $post_id,
array( array(
@ -80,14 +82,6 @@ if ( ! function_exists( 'fictioneer_build_story_schema' ) ) {
) )
); );
$page_title = fictioneer_get_seo_title(
$post_id,
array(
'default' => fictioneer_get_safe_title( $post_id ) . ' &ndash; ' . FICTIONEER_SITE_NAME,
'skip_cache' => true
)
);
// Collect visible chapters // Collect visible chapters
if ( ! empty( $chapters ) ) { if ( ! empty( $chapters ) ) {
foreach ( $chapters as $chapter_id ) { foreach ( $chapters as $chapter_id ) {