Opened 2 months ago
Last modified 2 months ago
#59510 new enhancement
Add filter for the block-template viewport meta tag
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.4 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
The base block-template.php used for full site editing does not provide a hook for modifying the viewport meta tag. Despite being inserted into wp_head by the _block_template_viewport_meta_tag
action hook, the actual tag is basically hard coded and untouchable: https://github.com/WordPress/wordpress-develop/blob/00ed25e2c9b20607418cbe8a6103c336d1bf92bd/src/wp-includes/block-template.php#L273-L275.
This ticket introduces a new filter which allows for customization of this meta tag.
Change History (2)
This ticket was mentioned in PR #5360 on WordPress/wordpress-develop by @joemaller.
2 months ago
#1
- Keywords has-patch added
@joemaller commented on PR #5360:
2 months ago
#2
Without this filter, the meta tag can be changed by first removing the _block_template_viewport_meta_tag
action:
add_action('pre_get_posts', function() {
remove_action('wp_head', '_block_template_viewport_meta_tag', 0);
});
And then hooking in a new meta tag:
add_action('wp_head', function() {
echo '<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />' . "\n";
}, 0);
With the new filter, just this:
add_filter('block_template_viewport_meta_tag', function() {
return '<meta name="viewport" content="width=device-width" />';
});
This ticket introduces a new filter which allows for customization of the block-template's viewport meta tag.
Despite being inserted into wp_head by the _block_template_viewport_meta_tag action hook, the actual tag is basically hard coded and untouchable.