Created
March 14, 2025 16:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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