I’ll build this as a strong WordPress theme template part for inc/template-parts/content-page.php, with safe fallbacks, accessibility, schema, page meta, featured image, pagination, child-page navigation, comments support, and hook points for future expansion.
Yes friend — in rx theme/inc/template-parts/content-page.php, you can make this file very powerful. This file should control single WordPress page content output, not global enqueue/cache/sitemap logic. WordPress officially supports reusable template parts with get_template_part(), and page/comment rendering can safely use template tags like the_content(), wp_link_pages(), and comments_template().
Replace your inc/template-parts/content-page.php with this advanced version:
<?php
/**
* Template part for displaying page content.
*
* File: inc/template-parts/content-page.php
*
* @package Rx_Theme
*/
defined( 'ABSPATH' ) || exit;
global $post;
if ( ! $post instanceof WP_Post ) {
return;
}
/**
* ------------------------------------------------------------
* Basic page variables
* ------------------------------------------------------------
*/
$rx_page_id = get_the_ID();
$rx_page_title = get_the_title( $rx_page_id );
$rx_page_permalink = get_permalink( $rx_page_id );
$rx_page_author_id = (int) get_post_field( 'post_author', $rx_page_id );
$rx_page_parent_id = (int) wp_get_post_parent_id( $rx_page_id );
$rx_show_title = apply_filters( 'rx_theme_show_page_title', true, $rx_page_id );
$rx_show_meta = apply_filters( 'rx_theme_show_page_meta', false, $rx_page_id );
$rx_show_thumb = apply_filters( 'rx_theme_show_page_thumbnail', true, $rx_page_id );
$rx_show_edit = apply_filters( 'rx_theme_show_page_edit_link', true, $rx_page_id );
$rx_article_classes = array(
'rx-page',
'rx-page-content',
'rx-entry',
'rx-entry-page',
);
if ( has_post_thumbnail( $rx_page_id ) ) {
$rx_article_classes[] = 'rx-has-featured-image';
} else {
$rx_article_classes[] = 'rx-no-featured-image';
}
if ( $rx_page_parent_id ) {
$rx_article_classes[] = 'rx-child-page';
} else {
$rx_article_classes[] = 'rx-parent-page';
}
if ( is_page_template() ) {
$rx_article_classes[] = 'rx-custom-page-template';
}
/**
* ------------------------------------------------------------
* Schema data
* ------------------------------------------------------------
*/
$rx_schema_type = apply_filters( 'rx_theme_page_schema_type', 'WebPage', $rx_page_id );
$rx_schema = array(
'@context' => 'https://schema.org',
'@type' => $rx_schema_type,
'mainEntityOfPage' => array(
'@type' => 'WebPage',
'@id' => esc_url_raw( $rx_page_permalink ),
),
'headline' => wp_strip_all_tags( $rx_page_title ),
'url' => esc_url_raw( $rx_page_permalink ),
'datePublished' => get_the_date( DATE_W3C, $rx_page_id ),
'dateModified' => get_the_modified_date( DATE_W3C, $rx_page_id ),
'author' => array(
'@type' => 'Person',
'name' => get_the_author_meta( 'display_name', $rx_page_author_id ),
),
'publisher' => array(
'@type' => 'Organization',
'name' => get_bloginfo( 'name' ),
'url' => home_url( '/' ),
),
);
if ( has_post_thumbnail( $rx_page_id ) ) {
$rx_thumb_id = get_post_thumbnail_id( $rx_page_id );
$rx_thumb = wp_get_attachment_image_src( $rx_thumb_id, 'full' );
if ( ! empty( $rx_thumb[0] ) ) {
$rx_schema['image'] = esc_url_raw( $rx_thumb[0] );
}
}
$rx_schema = apply_filters( 'rx_theme_page_schema', $rx_schema, $rx_page_id );
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( $rx_article_classes ); ?> itemscope itemtype="https://schema.org/<?php echo esc_attr( $rx_schema_type ); ?>">
<?php
/**
* Hook: Before page article content.
*/
do_action( 'rx_theme_before_page_article', $rx_page_id );
?>
<script type="application/ld+json" class="rx-page-schema">
<?php echo wp_json_encode( $rx_schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT ); ?>
</script>
<?php if ( $rx_show_thumb && has_post_thumbnail( $rx_page_id ) ) : ?>
<figure class="rx-page-featured-image rx-entry-featured-image">
<a href="<?php echo esc_url( $rx_page_permalink ); ?>" aria-label="<?php echo esc_attr( $rx_page_title ); ?>">
<?php
the_post_thumbnail(
apply_filters( 'rx_theme_page_thumbnail_size', 'large', $rx_page_id ),
array(
'class' => 'rx-page-thumbnail-img',
'loading' => is_singular() ? 'eager' : 'lazy',
'decoding' => 'async',
'itemprop' => 'image',
'alt' => esc_attr( get_post_meta( get_post_thumbnail_id( $rx_page_id ), '_wp_attachment_image_alt', true ) ?: $rx_page_title ),
)
);
?>
</a>
<?php
$rx_thumb_caption = wp_get_attachment_caption( get_post_thumbnail_id( $rx_page_id ) );
if ( $rx_thumb_caption ) :
?>
<figcaption class="rx-page-featured-caption">
<?php echo wp_kses_post( $rx_thumb_caption ); ?>
</figcaption>
<?php endif; ?>
</figure>
<?php endif; ?>
<header class="rx-page-header entry-header">
<?php
/**
* Hook: Before page title.
*/
do_action( 'rx_theme_before_page_title', $rx_page_id );
?>
<?php if ( $rx_show_title ) : ?>
<?php if ( is_front_page() ) : ?>
<h1 class="rx-page-title entry-title" itemprop="headline">
<?php echo esc_html( $rx_page_title ); ?>
</h1>
<?php else : ?>
<h1 class="rx-page-title entry-title" itemprop="headline">
<?php the_title(); ?>
</h1>
<?php endif; ?>
<?php endif; ?>
<?php
/**
* Hook: After page title.
*/
do_action( 'rx_theme_after_page_title', $rx_page_id );
?>
<?php if ( $rx_show_meta ) : ?>
<div class="rx-page-meta entry-meta">
<span class="rx-page-author">
<?php esc_html_e( 'By', 'rx-theme' ); ?>
<a href="<?php echo esc_url( get_author_posts_url( $rx_page_author_id ) ); ?>" rel="author">
<?php echo esc_html( get_the_author_meta( 'display_name', $rx_page_author_id ) ); ?>
</a>
</span>
<span class="rx-page-published">
<?php esc_html_e( 'Published:', 'rx-theme' ); ?>
<time datetime="<?php echo esc_attr( get_the_date( DATE_W3C, $rx_page_id ) ); ?>" itemprop="datePublished">
<?php echo esc_html( get_the_date( '', $rx_page_id ) ); ?>
</time>
</span>
<span class="rx-page-modified">
<?php esc_html_e( 'Updated:', 'rx-theme' ); ?>
<time datetime="<?php echo esc_attr( get_the_modified_date( DATE_W3C, $rx_page_id ) ); ?>" itemprop="dateModified">
<?php echo esc_html( get_the_modified_date( '', $rx_page_id ) ); ?>
</time>
</span>
</div>
<?php endif; ?>
</header>
<?php
/**
* Hook: Before page content.
*/
do_action( 'rx_theme_before_page_content', $rx_page_id );
?>
<div class="rx-page-body entry-content" itemprop="text">
<?php
/**
* Main WordPress page content.
*/
the_content();
/**
* Multi-page page support.
*/
wp_link_pages(
array(
'before' => '<nav class="rx-page-links page-links" aria-label="' . esc_attr__( 'Page navigation', 'rx-theme' ) . '"><span class="rx-page-links-title">' . esc_html__( 'Pages:', 'rx-theme' ) . '</span>',
'after' => '</nav>',
'link_before' => '<span class="rx-page-link-number">',
'link_after' => '</span>',
'pagelink' => '<span class="screen-reader-text">' . esc_html__( 'Page', 'rx-theme' ) . ' </span>%',
'separator' => '',
)
);
?>
</div>
<?php
/**
* Hook: After page content.
*/
do_action( 'rx_theme_after_page_content', $rx_page_id );
?>
<?php
/**
* ------------------------------------------------------------
* Page excerpt / summary block
* ------------------------------------------------------------
*/
$rx_page_excerpt = has_excerpt( $rx_page_id ) ? get_the_excerpt( $rx_page_id ) : '';
if ( apply_filters( 'rx_theme_show_page_excerpt_box', false, $rx_page_id ) && $rx_page_excerpt ) :
?>
<aside class="rx-page-summary-box" aria-label="<?php esc_attr_e( 'Page summary', 'rx-theme' ); ?>">
<h2 class="rx-page-summary-title">
<?php esc_html_e( 'Page Summary', 'rx-theme' ); ?>
</h2>
<p>
<?php echo esc_html( $rx_page_excerpt ); ?>
</p>
</aside>
<?php endif; ?>
<?php
/**
* ------------------------------------------------------------
* Parent page link
* ------------------------------------------------------------
*/
if ( apply_filters( 'rx_theme_show_parent_page_link', true, $rx_page_id ) && $rx_page_parent_id ) :
?>
<nav class="rx-parent-page-nav" aria-label="<?php esc_attr_e( 'Parent page', 'rx-theme' ); ?>">
<a class="rx-parent-page-link" href="<?php echo esc_url( get_permalink( $rx_page_parent_id ) ); ?>">
<span aria-hidden="true">←</span>
<?php
printf(
esc_html__( 'Back to %s', 'rx-theme' ),
esc_html( get_the_title( $rx_page_parent_id ) )
);
?>
</a>
</nav>
<?php endif; ?>
<?php
/**
* ------------------------------------------------------------
* Child pages list
* ------------------------------------------------------------
*/
$rx_child_pages_args = apply_filters(
'rx_theme_child_pages_args',
array(
'post_type' => 'page',
'post_parent' => $rx_page_id,
'post_status' => 'publish',
'orderby' => 'menu_order title',
'order' => 'ASC',
'posts_per_page' => -1,
'no_found_rows' => true,
),
$rx_page_id
);
$rx_child_pages = new WP_Query( $rx_child_pages_args );
if ( apply_filters( 'rx_theme_show_child_pages', true, $rx_page_id ) && $rx_child_pages->have_posts() ) :
?>
<section class="rx-child-pages-section" aria-labelledby="rx-child-pages-title-<?php echo esc_attr( $rx_page_id ); ?>">
<h2 id="rx-child-pages-title-<?php echo esc_attr( $rx_page_id ); ?>" class="rx-child-pages-title">
<?php esc_html_e( 'More Pages', 'rx-theme' ); ?>
</h2>
<div class="rx-child-pages-grid">
<?php
while ( $rx_child_pages->have_posts() ) :
$rx_child_pages->the_post();
$rx_child_id = get_the_ID();
?>
<article class="rx-child-page-card" id="rx-child-page-<?php echo esc_attr( $rx_child_id ); ?>">
<?php if ( has_post_thumbnail( $rx_child_id ) ) : ?>
<a class="rx-child-page-thumb-link" href="<?php the_permalink(); ?>" aria-label="<?php the_title_attribute(); ?>">
<?php
the_post_thumbnail(
'medium',
array(
'class' => 'rx-child-page-thumb',
'loading' => 'lazy',
'decoding' => 'async',
)
);
?>
</a>
<?php endif; ?>
<h3 class="rx-child-page-card-title">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h3>
<?php if ( has_excerpt( $rx_child_id ) ) : ?>
<p class="rx-child-page-excerpt">
<?php echo esc_html( wp_trim_words( get_the_excerpt( $rx_child_id ), 22, '…' ) ); ?>
</p>
<?php endif; ?>
<a class="rx-child-page-read-more" href="<?php the_permalink(); ?>">
<?php esc_html_e( 'Read more', 'rx-theme' ); ?>
<span class="screen-reader-text">
<?php the_title(); ?>
</span>
</a>
</article>
<?php endwhile; ?>
</div>
</section>
<?php
wp_reset_postdata();
endif;
?>
<?php
/**
* ------------------------------------------------------------
* Page custom fields display
* Off by default for safety.
* Enable with:
* add_filter( 'rx_theme_show_page_custom_fields', '__return_true' );
* ------------------------------------------------------------
*/
if ( apply_filters( 'rx_theme_show_page_custom_fields', false, $rx_page_id ) ) :
$rx_custom_fields = get_post_custom( $rx_page_id );
if ( ! empty( $rx_custom_fields ) ) :
?>
<section class="rx-page-custom-fields" aria-labelledby="rx-custom-fields-title-<?php echo esc_attr( $rx_page_id ); ?>">
<h2 id="rx-custom-fields-title-<?php echo esc_attr( $rx_page_id ); ?>" class="rx-page-custom-fields-title">
<?php esc_html_e( 'Additional Information', 'rx-theme' ); ?>
</h2>
<dl class="rx-page-custom-fields-list">
<?php foreach ( $rx_custom_fields as $rx_meta_key => $rx_meta_values ) : ?>
<?php
if ( is_protected_meta( $rx_meta_key, 'post' ) ) {
continue;
}
?>
<dt>
<?php echo esc_html( ucwords( str_replace( array( '_', '-' ), ' ', $rx_meta_key ) ) ); ?>
</dt>
<dd>
<?php
$rx_clean_values = array_map(
static function ( $value ) {
return wp_strip_all_tags( maybe_unserialize( $value ) );
},
(array) $rx_meta_values
);
echo esc_html( implode( ', ', $rx_clean_values ) );
?>
</dd>
<?php endforeach; ?>
</dl>
</section>
<?php endif; ?>
<?php endif; ?>
<?php
/**
* ------------------------------------------------------------
* Attachments gallery
* Off by default.
* ------------------------------------------------------------
*/
if ( apply_filters( 'rx_theme_show_page_attachments', false, $rx_page_id ) ) :
$rx_attachments = get_children(
array(
'post_parent' => $rx_page_id,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order ID',
'order' => 'ASC',
)
);
if ( ! empty( $rx_attachments ) ) :
?>
<section class="rx-page-attachments" aria-labelledby="rx-page-attachments-title-<?php echo esc_attr( $rx_page_id ); ?>">
<h2 id="rx-page-attachments-title-<?php echo esc_attr( $rx_page_id ); ?>" class="rx-page-attachments-title">
<?php esc_html_e( 'Page Images', 'rx-theme' ); ?>
</h2>
<div class="rx-page-attachments-grid">
<?php foreach ( $rx_attachments as $rx_attachment ) : ?>
<figure class="rx-page-attachment-item">
<a href="<?php echo esc_url( wp_get_attachment_url( $rx_attachment->ID ) ); ?>">
<?php
echo wp_get_attachment_image(
$rx_attachment->ID,
'medium',
false,
array(
'class' => 'rx-page-attachment-image',
'loading' => 'lazy',
'decoding' => 'async',
)
);
?>
</a>
<?php if ( wp_get_attachment_caption( $rx_attachment->ID ) ) : ?>
<figcaption>
<?php echo wp_kses_post( wp_get_attachment_caption( $rx_attachment->ID ) ); ?>
</figcaption>
<?php endif; ?>
</figure>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
<?php endif; ?>
<footer class="rx-page-footer entry-footer">
<?php
/**
* Hook: Before page footer.
*/
do_action( 'rx_theme_before_page_footer', $rx_page_id );
?>
<?php if ( $rx_show_edit ) : ?>
<?php
edit_post_link(
sprintf(
wp_kses(
/* translators: %s: Name of current page. */
__( 'Edit <span class="screen-reader-text">%s</span>', 'rx-theme' ),
array(
'span' => array(
'class' => array(),
),
)
),
wp_kses_post( $rx_page_title )
),
'<span class="rx-edit-link edit-link">',
'</span>'
);
?>
<?php endif; ?>
<?php
/**
* Hook: After page footer.
*/
do_action( 'rx_theme_after_page_footer', $rx_page_id );
?>
</footer>
<?php
/**
* Hook: After page article content.
*/
do_action( 'rx_theme_after_page_article', $rx_page_id );
?>
</article>
<?php
/**
* ------------------------------------------------------------
* Comments
* ------------------------------------------------------------
* WordPress recommends loading comments conditionally where it makes sense.
*/
if ( apply_filters( 'rx_theme_show_page_comments', true, $rx_page_id ) ) {
if ( comments_open( $rx_page_id ) || get_comments_number( $rx_page_id ) ) {
comments_template();
}
}
?>
Optional helper filters for functions.php
Add these only when you want to turn features on/off:
<?php
/**
* Rx Theme page template-part controls.
*/
defined( 'ABSPATH' ) || exit;
/**
* Show page meta: author, published date, updated date.
*/
add_filter(
'rx_theme_show_page_meta',
function ( $show, $page_id ) {
return false;
},
10,
2
);
/**
* Show child pages under parent page.
*/
add_filter(
'rx_theme_show_child_pages',
function ( $show, $page_id ) {
return true;
},
10,
2
);
/**
* Show page summary box if excerpt exists.
*/
add_filter(
'rx_theme_show_page_excerpt_box',
function ( $show, $page_id ) {
return false;
},
10,
2
);
/**
* Show public custom fields.
*/
add_filter(
'rx_theme_show_page_custom_fields',
function ( $show, $page_id ) {
return false;
},
10,
2
);
/**
* Show image attachments gallery.
*/
add_filter(
'rx_theme_show_page_attachments',
function ( $show, $page_id ) {
return false;
},
10,
2
);
/**
* Disable comments on pages.
*/
add_filter(
'rx_theme_show_page_comments',
function ( $show, $page_id ) {
return true;
},
10,
2
);
Important note
This file is for page display only. Keep these in other files:
functions.php — theme setup, image sizes, menus, supports.inc/enqueue.php — CSS/JS loading.inc/template-tags.php — reusable small template functions.inc/template-parts/content.php — normal blog post content.inc/template-parts/content-page.php — static page content.