Recent

Lazy_Load_ModuleclassPro only

Lazy_Load_Module

Lazy loads related posts across all display methods (content filter, shortcode, widget, block, manual calls) by replacing them with a placeholder that’s swapped for the rendered output, fetched via the REST API, when it nears the viewport.

Display arguments round-trip through the placeholder as an HMAC-signed payload, so the REST endpoint renders exactly what the inline render would have produced while rejecting arbitrary client-supplied arguments. The signature is deterministic (no nonce) so pages stay compatible with long-lived page caches; an invalid signature degrades gracefully to rendering with the site settings.

The Pro Query block (a core Query Loop variation) is intentionally out of scope: it only flags the query vars and is rendered by core with arbitrary inner blocks, so it never passes through Display::related_posts().

Namespace: WebberZone\Contextual_Related_Posts\Pro
Since: 4.3.0
Source: includes/pro/class-lazy-load-module.php line 36

Methods

__construct()

Constructor.

Since: 4.3.0
Line: 71

public function __construct(  );

shortcode_defaults()

Add the lazy_load attribute to the shortcode defaults so it can be used as a per-instance override, e.g. [crp lazy_load=“0”].

Since: 4.3.0
Line: 88

public function shortcode_defaults( $defaults ): array;
Type Name Description
array $defaults Default shortcode settings.

Returns: array — Updated shortcode settings.

maybe_lazy_load()

Replace the related posts output with the lazy load placeholder.

Since: 4.3.0
Line: 104

public function maybe_lazy_load( $pre, $args, $post ): string|null;
Type Name Description
string|null $pre Pre-rendered output. Default null.
array $args Fully parsed arguments array.
\WP_Post $post Post object.

Returns: string|null — Placeholder HTML or the original value.

should_lazy_load()

Whether the related posts should be lazy loaded.

Since: 4.3.0
Line: 124

public function should_lazy_load( $post = ..., array $args = ... ): bool;
Type Name Description
\WP_Post|null $post Current post object.
array $args Arguments array. The lazy_load key acts as a

Returns: bool — Whether to lazy load the related posts.

lazy_load_placeholder()

Generate the lazy load placeholder for the related posts and enqueue the loader script.

Since: 4.3.0
Line: 167

public function lazy_load_placeholder( $post = ..., array $args = ... ): string;
Type Name Description
\WP_Post|int|null $post Post object or ID. Defaults to the current post.
array $args Arguments array used for the render.

Returns: string — Placeholder HTML. Empty string if the placeholder cannot be

enqueue_script()

Register and enqueue the lazy load script.

Since: 4.3.0
Line: 307

public function enqueue_script(  );

register_html_route()

Register the REST route that returns the rendered related posts HTML.

Since: 4.3.0
Line: 341

public function register_html_route(  );

get_item_html()

Get the rendered related posts HTML for a post.

Used by the lazy load script to fetch the related posts output. Display arguments are only honoured when they carry a valid signature generated by a server-side render; otherwise the output is rendered with the site settings.

Since: 4.3.0
Line: 381

public function get_item_html( $request ): \WP_Error|\WP_REST_Response;
Type Name Description
\WP_REST_Request $request WP Rest request.

Returns: \WP_Error|\WP_REST_Response — Response containing the rendered HTML.