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

Duplicated <title> tag #34106

Open
2 tasks done
rufus87 opened this issue Aug 17, 2021 · 5 comments
Open
2 tasks done

Duplicated <title> tag #34106

rufus87 opened this issue Aug 17, 2021 · 5 comments

Comments

@rufus87
Copy link
Task lists! Give feedback

@rufus87 rufus87 commented Aug 17, 2021

Description

There is a great possibility to overwrite templates in FSE mod. But as soon as any template is overwritten and it content is served from database, <title> tag rendered in is duplicated, because there are 2 actions callbacks wit different names attached to 'wp_head' action:

  1. add_action( 'wp_head', '_block_template_render_title_tag', 1 ); in wp-includes/block-template.php line 84
  2. add_action( 'wp_head', 'gutenberg_render_title_tag', 1 ); in wp-content/plugins/gutenberg/lib/full-site-editing/template-loader.php line 100

this happens only if FSE theme template is edited and saved in FSE mod in database.

Step-by-step reproduction instructions

  1. Enable any FSE theme
  2. Overwrite any page/post template in FSE
  3. Render page/post

Screenshots, screen recording, code snippet

image

Environment info

No response

Pre-checks

  • I have searched the existing issues.
  • I have tested with all plugins deactivated except Gutenberg.
@fwazeter
Copy link

@fwazeter fwazeter commented Aug 18, 2021

EDIT: Seems another member was able to remove / comment the lines and the issue went away - I tested across multiple browsers, but I'm going to assume that my experiment below is caused by caching or local being weird.

Referencing conversation happening in #core-editor slack about this.

TT1 Blocks Testing
Gutenberg File Linked (template-loader.php).

The viewport meta tag is also being repeated when a wp_template CPT is loaded, not just the title tag.

<meta name="viewport" content="width=device-width, initial-scale=1">

Removed lines 94-100 in GB template-loader.php:

	// Add hooks for template canvas.
	// Add viewport meta tag.
	add_action( 'wp_head', 'gutenberg_viewport_meta_tag', 0 );

	// Render title tag with content, regardless of whether theme has title-tag support.
	remove_action( 'wp_head', '_wp_render_title_tag', 1 );    // Remove conditional title tag rendering...
	add_action( 'wp_head', 'gutenberg_render_title_tag', 1 ); // ...and make it unconditional.

Reloaded plugin, the same error occurs when saving a brand new template (saved a new one in case the old edited file did not re-render on plugin code change).

It appears like there is another file / call somewhere that is causing the duplication.

@gziolo
Copy link
Member

@gziolo gziolo commented Aug 18, 2021

It looks like it's an issue with how the same functionality is handled in the plugin to bridge older versions of WordPress. Related part here that uses gutenberg_render_title_tag callback:

// Render title tag with content, regardless of whether theme has title-tag support.
remove_action( 'wp_head', '_wp_render_title_tag', 1 ); // Remove conditional title tag rendering...
add_action( 'wp_head', 'gutenberg_render_title_tag', 1 ); // ...and make it unconditional.

In the WordPress core it's handled with _block_template_render_title_tag :

https://github.com/WordPress/wordpress-develop/blob/b97fe776da274ed6349c795d495dcb72968e698f/src/wp-includes/block-template.php#L82-L84

The simplest approach would be to remove the wp_head action with _block_template_render_title_tag callback in the Gutenberg plugin. There might be also room for improvements in how we polyfill older versions of WordPress that don't have the functionality added in WP 5.8.

@fwazeter
Copy link

@fwazeter fwazeter commented Aug 18, 2021

Technically, couldn't the polyfill be as simple as a WP Version check in the template loader in GB?

@gziolo
Copy link
Member

@gziolo gziolo commented Aug 18, 2021

Technically, couldn't the polyfill be as simple as a WP Version check in the template loader in GB?

Sure, the usual approach used in the plugin is to check if the function is defined, so here if there is no _block_template_render_title_tag then you either define the same function or define a different one and register in a hook

@fwazeter
Copy link

@fwazeter fwazeter commented Aug 18, 2021

That makes sense, at scale version tracking for different functions would become a nightmare over updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants