Skip to content

Add a Code Library snippet for CRP custom HTML rendering #2

Description

@ajaydsouza

Goal

Add a copy-and-paste example showing how to replace Contextual Related Posts default markup with the crp_custom_template filter while leaving CRP responsible for matching and selecting the related posts.

Existing coverage

crp-api-example.php renders a direct CRP_Query loop, and crp-add-categories.php changes one list item. Neither demonstrates full output replacement through crp_custom_template.

Deliverables

  • Add contextual-related-posts/crp-custom-template.php or an equally clear filename under the display category.
  • Register a uniquely prefixed callback on crp_custom_template and document $results as related post IDs and $args as the parsed display arguments.
  • Render a small accessible wrapper and list with escaped permalinks, titles, and optional thumbnails, without assuming a particular theme.
  • Return a non-empty HTML string when taking over the output and return null when the default renderer should continue.
  • Add a matching Markdown companion under src/content/snippets/contextual-related-posts/ with installation guidance, requiresPro: false, and the hook reference.
  • Explain that the filter applies to automatic output and explicit display methods such as the shortcode, widget, block, and manual calls.
  • Include the caching caveat: returned custom HTML is cached when CRP HTML output caching is enabled, so request- or user-specific markup needs caching disabled for that call.

This is a reusable renderer example, not a YARPP-compatible yarpp-template-*.php filesystem mechanism. The CRP API documentation update is tracked separately in contextual-related-posts#229.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions