I was shown a similar plugin for Wordpress and it had a neat function where the page title, url and meta description were previewed as they would appear in a Google search, styled to look like a Google search result.

In my experience trying to explain to clients how and why to input meta tags, it really helps to have that immediate visual of "Oh, this is how my page is going to look in a Google search"

I wonder if a preview like this could be something added to the Meta tags area of the node editing page? Maybe a preview of a Bing result as well?

Issue fork metatag-1539192

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

idflood’s picture

A coworker who use wordpress also showed me this preview thing and I definitely liked the idea. So +1 for this feature (as a submodule eventually).

idflood’s picture

Issue summary: View changes

had html in text that wasn't showing

sirtet’s picture

Issue summary: View changes

+1, or +10...
This is a good example of real time preview:
http://www.sistrix.de/serp-snippet-generator/

simon georges’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Priority: Minor » Normal
StatusFileSize
new138.04 KB
new154.66 KB

Both https://www.drupal.org/project/simple_seo_preview & https://www.drupal.org/project/yoast_seo are doing this, and I feel it brings a great value to content editors. I attached a screenshot of both modules so you can see what it displays.

What do you think?

damienmckenna’s picture

I think there are a number of different previews that could be displayed:

  • Search results preview.
  • Twitter card preview.
  • Facebook share preview.

Yes, I think these could be added to Metatag, I'm just not sure of the UX.

simon georges’s picture

I was thinking the simplest one is the SERP preview (because Twitter needs a preview per card type, and facebook needs an image), but the Search result preview should be hookable, so Schema.org Metatag can adds some information for reviews, events, breadcrumb, and so on.

But a first approach could be to simply add the SERP preview immediatly under Title and Description metatags, considering they are the first two ones to be displayed in the Metatag fieldset.

What other UX were you thinking about? A modal?

damienmckenna’s picture

Title: Preview of search engine results » Live preview of meta tag output (D8)
Related issues: +#1932404: Live preview of meta tag output (D7)

flyke made their first commit to this issue’s fork.

flyke’s picture

Version: 8.x-1.x-dev » 2.0.x-dev

flyke changed the visibility of the branch 1539192-live-preview-of to hidden.

flyke’s picture

StatusFileSize
new167.7 KB

I added a new submodule 'metatag_serp_preview' (in branch 1539192-serp-preview) that does this when its enabled.

flyke’s picture

Status: Active » Needs review
damienmckenna’s picture

Status: Needs review » Needs work

Thank you for putting this together.

I don't think this would work super well:

  • It assumes the Metatag field is called "field_metatags".
  • It only works when the form is initially loaded.

I think the correct approach would be either an AJAX callback of some sort, possibly as a response to a button being clicked, or to do it all in JS on the page.

flyke’s picture

For determining if the current Node has a metatags field, that part of the code is ok and automatically gets the correct fieldname of the node if it has a metatag field.

For altering the metatag form on the node edit form to add a new form item: yes, at this moment I was not sure on how to dynamically get the correct form element key. I just inspected the form and saw that I wanted to add a new form element in $form['field_metatags']['widget'][0]['basic']. Is the form element key 'field_metatags' always the exact same value as the machine name of the metatag field on the node entity ? Because that would be an easy fox then, I do dynamically have the correct node field machine name.

About the Ajax possibility: I thought about it when I created this but it quite frankly seemed too difficult for me. For the most part because you can use tokens in the meta title and description and the JS code needs to handle and convert those. And if you have a token for description that automatically generates text from layoutbuilder blocks on the node, or from paragraphs on the node, I honestly have no Idea of how to handle that via Ajax without saving the page.

But if you really want that, feel free to contribute, it would be very welcoming if you could create a patch or MR for that.

damienmckenna’s picture

The $form['field_metatags'] variable will always depend upon how it's configured on the site, it should be $form['$metatag_fieldname'].

This is a difficult issue to accomplish, because Drupal's form API is so complex and because there can be so many different possibilities on how the meta tags are configured, that's why there hasn't been a solid implementation of this functionality yet.