Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow html in pagination labels #60878

Open
huubl opened this issue Apr 18, 2024 · 0 comments
Open

Allow html in pagination labels #60878

huubl opened this issue Apr 18, 2024 · 0 comments
Labels
[Block] Query Pagination Affects the Query Pagination Block - used for pagination within the Query Loop Block [Type] Enhancement A suggestion for improvement.

Comments

@huubl
Copy link
Contributor

huubl commented Apr 18, 2024

What problem does this address?

The current implementation of the core/query-pagination-previous and core/query-pagination-next blocks in Gutenberg use esc_html to escape the label text, which doesn't allow any HTML tags. This limits the freedom to set a label as Previous <span class="hide-on-mobile">Page</span>:

Right now this doesn't work:

function render_block_data_pagination($parsed_block)
{
	if ('core/query-pagination-previous' === $parsed_block['blockName']) {
		$parsed_block['attrs']['label'] = 'Previous <span class="hide-on-mobile">Page</span>';
	}

	return $parsed_block;
}
add_filter('render_block_data', 'render_block_data_pagination', 10, 3);

What is your proposed solution?

Switch from esc_html to wp_kses for escaping the label text, allowing the <span> tag, and maybe some other tags. This would give developers more freedom. Here's an example of how the code might look:

$allowed_html = array(
    'span' => array()
);

$label_text = isset($attributes['label']) && !empty($attributes['label'])
    ? wp_kses($attributes['label'], $allowed_html)
    : $default_label;
@huubl huubl added the [Type] Enhancement A suggestion for improvement. label Apr 18, 2024
@t-hamano t-hamano added the [Block] Query Pagination Affects the Query Pagination Block - used for pagination within the Query Loop Block label Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Pagination Affects the Query Pagination Block - used for pagination within the Query Loop Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants