Skip to content

Instantly share code, notes, and snippets.

@joemaller
Created March 14, 2025 16:02
Show Gist options
  • Save joemaller/ffdef994d3dadc54d057ad7330ae7479 to your computer and use it in GitHub Desktop.
Save joemaller/ffdef994d3dadc54d057ad7330ae7479 to your computer and use it in GitHub Desktop.
Experiment for wrapping and changing the prev/next arrows in the WordPress Pagination Block
<?php
/**
* Experiment to rewrite the render_callbacks of the pagination prev/next blocks to swap the arrow for something else
*/
add_filter('register_block_type_args', __NAMESPACE__ . '\\swap_render_callback', 10, 2);
/**
* Replace the pagination-prev/next render_callback with a function which wraps the native function's return value
*/
function swap_render_callback($args, $block_type)
{
if (
$block_type === 'core/query-pagination-previous' ||
$block_type === 'core/query-pagination-next'
) {
$args['render_callback'] = __NAMESPACE__ . '\\pagination_prev_next_render_callback';
}
return $args;
}
/**
* Wrap the native callback function
*/
function pagination_prev_next_render_callback($attributes, $content, $block)
{
$native =
$block->name === 'core/query-pagination-previous'
? \render_block_core_query_pagination_previous($attributes, $content, $block)
: \render_block_core_query_pagination_next($attributes, $content, $block);
$newArrow = preg_replace(['/←/u', '/→/u'], ['⬅️', '➡️'], $native);
return $newArrow;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment