Referring to http://drupal.org/node/1283362

Make Metatag work with Display Suite (http://drupal.org/project/ds)

Comments

sebish’s picture

That would be great, indeed. Subscribing.

minus’s picture

Subscribing

Shadlington’s picture

Subscribing

pazap47’s picture

sub

atlea’s picture

Subscribe

mjpa’s picture

Version: 7.x-1.0-alpha2 »
Status: Active » Needs review
StatusFileSize
new573 bytes

Found out you can make metatags work with display suite if you manually add the fields via the "Extra fields" setting on admin/structure/ds/extras, but that's a bad way to do things.

Working out how that works, it seems all this module needs to do is add the field to the 'display' context in hook_field_extra_fields(), attaching a patch that does that only if Display Suite is enabled - it may not affect things if the field is always added to the display context though but will need testing.

Anonymous’s picture

Version: 7.x-1.0-alpha3 »
Assigned: biosonic » Unassigned

Great, patch works for me.

For others, there is a new field "Meta tag" in the DS content type display setup page. Put the Meta tag field in a visual area (head) and the Meta discription is in the HTML head. Visitors don't see the Meta tag field.

Thanks

biosonic’s picture

Version: » 7.x-1.0-alpha3
Assigned: Unassigned » biosonic
Issue tags: +meta tag

You saved the day :)

sammyd56’s picture

atlea’s picture

Re. testing - have been using this without issues for the past five days. Seems to work great. Thank you. :)

sammyd56’s picture

Status: Needs review » Reviewed & tested by the community

Seems like a resounding RTBC!

heyyo’s picture

Since I Applyed the patch mentionned in #6 , I successfully get description and og:description inserted in the HTML head, but the image field I set in metatag setting for "Open Graph image: " in a particular content type is not set.

I'm using a media field, and in the devel token tab, my picture is correctly displayed, so the token is filled correctly.

Anyone has this problem too ?

EDIT: I have tested with a regular image field, and the og:image is correctly displayed. So it seems that an updated patch is needed...

dave reid’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/metatag.moduleundefined
@@ -546,6 +546,13 @@ function metatag_field_extra_fields() {
+            'description' => t('Meta tag module form elements.'),

This probably isn't a good description since these are not actually form elements when being displayed. Maybe something like 'Rendered meta tags' or similar?

mjpa’s picture

Status: Needs work » Needs review
StatusFileSize
new562 bytes

Updated patch with a better description - should read what I copy/paste in the early hours of the day :)

heyyo: I believe this issue is only about the metatags as a whole not being added to the page, so if there is certain metatags not being added that should be a separate issue.

Status: Needs review » Needs work
Issue tags: -meta tag

The last submitted patch, metatag_ds-1284852-14.patch, failed testing.

mjpa’s picture

Status: Needs work » Needs review
Issue tags: +meta tag

#14: metatag_ds-1284852-14.patch queued for re-testing.

idflood’s picture

Status: Needs review » Needs work

The patch in #14 looks good but it doesn't change anything for me. My issue it that both keywords and description doesn't show up in the head. Maybe an update hook missing?

I've cleared all caches, ran update.php, disabled and then enabled the metatag module and finally visited the node type pages in a last desperate move. What did I miss?

idflood’s picture

Status: Needs work » Needs review

sorry, should have read more carefully this issue. Finally followed the guide in #7 and it's working nicely.
This isn't the expected behavior I think, so maybe a little help text somewhere would be good to avoid lots of duplicate issues.

silkogelman’s picture

Version: » 7.x-1.x-dev

Applied the patch at #14 and the instructions at #7.
It works perfectly, all Meta tags show up in the header now (using Display Suite).

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Time for a status change r&tbtc

jyve’s picture

Tested and works great.

I have to say it feels weird that I need to do this just to get header information to work.

glenn_jones’s picture

Thx for the great work guys.

Never the less… i think there is still a problem if you use display suite with the panels UI.
It seems to be unpossible to add the field metatags.

Anybody?

Glenn

Duplika’s picture

I've updated to the latest dev version and I'm still unable to find the field "Meta tag" at admin/structure/types/manage/mynodetype/display but since I'm only able to place fields in the head area (only enable or disable, example here), maybe I should enable or change something else.

Any ideas will be appreciated.

minus’s picture

I had to enable the patch in #14, even with the latest dev.

monil-dupe’s picture

It is better if patches implement to the main code that we don't need to install patches.

InTheLyonsDen’s picture

Patch #14 worked for me. Thanks!!!

matthewv789’s picture

This didn't really seem like an ideal solution for me.

First, it requires patching the module itself, which I like to avoid if possible, but will if it offers a complete solution.

Second, it requires manually going in and assigning the meta tags field on each Content Type and View Mode through Display Suite. This can be a lot of work, is easy to overlook, and isn't really intuitive or logical (ie, you're assigning it to some visible region of the page where it's not even showing up).

Third, it doesn't even work in all cases - Panels has already been mentioned, and I had trouble on content types with multiple View Modes. So a good chunk of the pages on my site STILL didn't display meta tags.

So I ended up going a different route, which only modifies my custom theme and works on all pages with no further effort. In my theme's html.tpl.php, I added this PHP code at the top (you could modify this if you have metatags on things besides nodes):

if ((arg(0) == 'node') && is_numeric(arg(1))) {
  $node = node_load(arg(1));
  $metatags = metatag_metatags_load('node',$node->nid);
}

Then just below, I replaced:

<title><?php print $head_title; ?></title>

with this, which covered the meta tags we were interested in (primarily title tag and meta description) - others could be added as needed:

<title><?php if (!empty($metatags['title']['value'])) { print $metatags['title']['value']; } else { print $head_title; } ?></title>
<?php if (!empty($metatags['keywords']['value'])) { ?><meta name="keywords" content="<?php print $metatags['keywords']['value']; ?>" />
<?php } if (!empty($metatags['description']['value'])) { ?><meta name="description" content="<?php print $metatags['description']['value']; ?>" />
<?php } ?>
alwor’s picture

Thanks #27 - just used the bottom part and it worked like a charm with my Omega subtheme + panels, and it even made the Page Title module work for me as well!

sandergo90’s picture

#27 works like a charm thanks for this but if I may correct it, you better do not do a node_load. It isn't neccessary. When you have the arg(1) you already have your node ID. And if you want to do it even better you put your metatags in a preprocess function like this:

function template_preprocess(&$variables) {
if ((arg(0) == 'node') && is_numeric(arg(1))) {
$node_id = arg(1);
$metatags = metatag_metatags_load('node',$node_id);
$variables['metatags'] = $metatags;
}
}

By this way you can access the variable $metatags in your html.tpl :)

dimitriseng’s picture

Just to confirm that #14 works for me too, thanks! Is this the final solution then? Or should we look for a more generic solution? I know that there are other issues for integration with panels etc, such as #1212072: Panels Meta.

rvolk’s picture

I like to share my solution, since i spend round about 10 hours with this issue now. This solution can be used as a module or theme implementation and is definitely not the last solution, but works great for my use case!

}

/**
 * Implements hook_field_attach_view_alter().
 * This is a little hack to the metatags module to support display suite view_modes,
 * if your default node full page view_mode is not "full" because of the ds_switch option.
 */
function HOOK_field_attach_view_alter(&$output, $context) {
	if (isset($context['entity']->ds_switch) && $context['entity']->ds_switch == $context['view_mode']) {
		$context['view_mode'] = 'full';
		// metatag_field_attach_view_alter failed before, because 'full' view_mode is required
		metatag_field_attach_view_alter($output, $context);
	}
}

/**
 * Implements hook_preprocess_page().
 */
function HOOK_preprocess_page(&$vars) {
	if (isset($vars['node'])) {
		// metatags mapping for display suite and panel view modes on node pages
		$uri = entity_uri('node', $vars['node']);
		if (!empty($uri) && current_path() == $uri['path']) {
			$vars['page']['content']['content']['content']['metatags'] += $vars['page']['content']['content']['content']['system_main']['nodes'][$vars['node']->nid]['metatags'];
		}
	}
}

Of course the deep linked $vars could be validated if they exists before, but i like to keep this example simple.

As you could see we have to map the metatags from the node entity to the page content metatags. There will be already a global sub array, but the last entry wins. Please remember that the metatags for your node will only be generated in 'full' view_mode!

Feedback would be appreciated!

Katrina B’s picture

I definitely would like to see a permanent solution for this; I use Display Suite quite a lot -- and I need to be able to have metatags on the sites I work on as well.

danny englander’s picture

I have tried #31 above both as a module and template preprocess without success. I'm not a fan of #27 as my theme does not have an html.tpl.php and I don't want to really copy that file over from core into my theme at this point because I am too far into theming my site to introduce a major new page like that with all those alterations, I think the ramifications are far reaching. I don't really have a lot of Display Suite pages in my site, only a few so I'd probably even go back to making a custom node type tpl page instead and ditch Display Suite to get this working.

Therefore, I'd like to try the patch in #14 but I am confused as it's from October 30th 2011 but the latest dev of Metatag is from December of 2011. Did this patch never make it into the dev? If not what dev should I apply the patch against? Thanks.

danny englander’s picture

Ok I applied the patch from #14 and it works but I agree with matthewv789 from #27 above:

... and isn't really intuitive or logical (ie, you're assigning it to some visible region of the page where it's not even showing up).

This does seem awkward to me to assign a metatag to a visible region i.e. "right" and it says: "Visible", I think that could be confusing for site builders.

carsonblack’s picture

I can also confirm that #14 works as advertised.
I can also understand #27 issue with UX, but I think the solution proposed there is just too heavy-handed, could introduce the possibility of security issues, make your theme unable to be updated, and, as I understand it, is bad form (Sorry, I don't mean to be a party-pooper or mean spirited I know a lot of people do this kind of thing).
I like where #31 is going, it's the module-side equivalent of what #27 with a little bit of the #29 wants to do, but it only works for one view mode.
Perhaps there is some sort of compromise in all of this? Maybe some kind of choice if ds is detected?
But really I think #14 is the solution to this issue. It works. Thanks mjpa!

slippast’s picture

This doesn't appear to have an entry over in the Display Suite queue. Perhaps this could be entered there as a feature request so it could be attacked from the other side? My sense is that this is a Display Suite problem.

BenK’s picture

Yes, I also think that tackling this from the Display Suite side may be best.

mstef’s picture

Works

silkogelman’s picture

Related issue in Display Suite module issue queue:
#1402402: Metatags from Metatags module

Alex_eav’s picture

Hello,
I'm trying to use patch from #14 but after that my site stopped to work and I see message 'Parse error: syntax error, unexpected '=', expecting ')' in /home2/eav/vodomerka.com.ua/sites/all/modules/metatag/metatag.module on line 621'
May be I'm doing something wrong. Can someone help me?

Anonymous’s picture

#14 works! Plain and simple

sircosta’s picture

As #40 said, the #14 .patch seems not to work correctly now. An error occurred: "patch unexpectedly ends in middle of line".

So I tried to make it manually with partially success changing de metatag.module.

I'm not an PHP expert so I was testing and finally replace this code in metatag.module (line 652)

function metatag_field_extra_fields() {
  $extra = array();
  foreach (entity_get_info() as $entity_type => $entity_info) {
    foreach (array_keys($entity_info['bundles']) as $bundle) {
      if (metatag_entity_supports_metatags($entity_type, $bundle)) {
        $extra[$entity_type][$bundle]['form']['metatags'] = array(
          'label' => t('Meta tags'),
          'description' => t('Meta tag module form elements.'),
          'weight' => 10,
        );
      }
    }
  }
  return $extra;
}

by this one:

function metatag_field_extra_fields() {
  $extra = array();
  foreach (entity_get_info() as $entity_type => $entity_info) {
    foreach (array_keys($entity_info['bundles']) as $bundle) {
    if (module_exists('ds')) {
          $extra[$entity_type][$bundle]['display']['metatags'] = array(
            'label' => t('Meta tags'),
            'description' => t('Meta tag module form elements.'),
            'weight' => 10,
        );
      }
    }
  }
  return $extra;
}

Making the changes detailed above and following the #7 instructions, 'Meta tags' woks fine in node/% paths but not in taxonomy/term/%. paths.

Any ideas why not working in taxonomy?

Thanks!

vidorado’s picture

Implementing #31 in template.php works great.

I'm using Omega theme and Display Suite with custom layout in full viewmode. When i configured no layout in the view mode (Drupal default output) metatags showed correctly. But after adding the code i can use whatever Display Suite layout and the metatags show too.

Really, the problem wasn't that i were having no metatags, it was that i was having global metatags instead of the overrided ones for node or my specific node-type.

I'm happy that i haven't had to follow #14 and #7 because i think it's not intuitive and needs too much work setting the Metatag field manually on all nodes.

Thanks R.Volk !!

pipicom’s picture

After I did #14 a new field "Meta tags" appeared at "admin/structure/types/manage/XXXXX/display" according to #7.
So yes, this works for me also..

dropbydrop’s picture

What is ETA for fixing this?
thanks

dropbydrop’s picture

Version: 7.x-1.x-dev » 7.x-1.0-alpha6
dropbydrop’s picture

#14 and #7 works

when this will be officially fixed?

mjpa’s picture

I'm going to go with "never will be fixed" unless Dave actually starts checking issues on his modules...

dropbydrop’s picture

Maybe with to croudfund (gather money) for a developer, or acquia has to look at this more.
We cannot expect a single person have the time to deal with it.

camorim’s picture

I tried #31 in template.php and it's magic!
Many thanks R. Volk

askibinski’s picture

patch in #14 works. Although it feels a bit weird having to place the metatags field in the content.

jackhutton’s picture

Version: 7.x-1.0-alpha6 » 7.x-1.x-dev

Love the power of being able to customize layout w Display Suite but sacrificing all of the SEO goodness of Metatag makes it a lot less viable.

I used the fix outlined in #31 R. Volk and referenced by #50 camorim and #43 vidorado and
Metatags are specific to the node ; using default mode in display suite are now rendering as expected.

Using an Omega SubTheme

Thank you for the work on metatag module. Its really a critical component.. Look forward to views integration w. metatag as well. I'll keep my eyes open for updates and a possible fix for this issue in a future release..
Again, thanks above and R. Volk for spending 10hrs wracking your brain to arrive at this solution and sharing it with the community.

damienmckenna’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)
Issue tags: +D7 stable release blocker

Rather than hacking away trying to get this working, and ultimately building work-arounds for an existing work-around in Metatag, the output logic has been re-written thanks to jenlampton and I'm hoping it works better now. Please try the latest -dev release and please let me know if it works as-is, and re-open the issue if it's still not working.

That said, please be aware that right now it doesn't let you override tags for taxonomy term pages due to a core bug, please keep an eye on #1700160: Support taxonomy term pages until taxonomy supports hook_entity_view() for further updates.

maomaohuhu’s picture

7.x-1.0-dev from #53 fixed the problem with Omega subtheme for me. Thanks a lot !

dropbydrop’s picture

fixed

jackhutton’s picture

This is a big deal! Thank You DamienMcKenna , jenlampton and maomaohuhu !

I installed the 7.x-1.x-dev version onto my local development site. Cleaned up the template.php code from above, cleared the caches -
The new version appears to be working great. It preserved my custom tags combinations for content types as well as for the few taxonomy terms

I was having conflicts w. the printer friendly version (print) module and that is no longer an issue as well

So thank you very much for this 'Leg Up' on this critical SEO component .

:)

damienmckenna’s picture

Status: Postponed (maintainer needs more info) » Fixed

With three positive reports I'm going to mark this as being fixed.

jmart’s picture

Status: Fixed » Needs work

I just tried the dev version and it did not work with Display Suite.

damienmckenna’s picture

@jmart: please provide more details. What types of entities did you test? What theme were you using? Did you make any customizations to the template files? Did you clear the site caches after updating?

jmart’s picture

StatusFileSize
new2.54 KB

Thank you Damien for responding.

After further investigation, it's not just Display Suite for the latest 7.x-1.x-dev version. It's not working on any of my nodes. I cleared the cache.

Theme: Custom theme with a Zen 7.x-3.1 base theme

I created two sites, one with recommended alpha and the other with dev. I created two pages, one a "Basic Page" content type and the other a "Animal" content type with a Full Content view mode and a Display Suite layout. I attached my template.php file. They are the same on both sites.

https://metatagalpha.dev.epcsite.com
Metatag version: 7.x-1.0-alpha6
Username: metatag
Password: metatag
https://www.metatagalpha.dev.epcsite.com/about - WORKS
https://www.metatagalpha.dev.epcsite.com/display-suite-giraffe - DOES NOT WORK

AND

https://www.meta-dev.dev.epcsite.com
Metatag version: 7.x-1.x-dev
Username: metatag
Password: metatag
https://www.meta-dev.dev.epcsite.com/about - DOES NOT WORK
https://www.meta-dev.dev.epcsite.com/display-suite-giraffe - DOES NOT WORK

damienmckenna’s picture

#jmart: Thanks. Did you change anything in the html, page or node tpl files? I wonder if this might be a case of theme incompatibility, but I'll definitely check it out.

jmart’s picture

StatusFileSize
new93.24 KB

I've attached the entire theme.

damienmckenna’s picture

@jmart: That's awesome, thanks, I'll try to test it this week.

damienmckenna’s picture

@jmart: Just to see, could you please change to another theme and see if the problem persists? Thanks.

jmart’s picture

I downloaded and enabled Stark 7.14 and Omega with the same results for both sites.

damienmckenna’s picture

Related and honestly a higher priority: #1708718: Ensure Meta tags work OOTB with Drupal core

I'm going to fix that and then see how to resolve this issue.

damienmckenna’s picture

Status: Needs work » Fixed

@jmart: Please try the -dev release again (download it on Aug 5th or later, to ensure it has the latest code commits) and let me know if it now works on the homepage and on node pages, this should now work correctly. Thanks.

damienmckenna’s picture

@jmart: btw I tried out your theme on my d7.dev testbed, and on a node page with an overridden description & title, using the current stable release of DS I get the following meta tags:

<meta property="og:url" content="http://d7.dev/node/1" />
<meta name="description" content="aye caramba!" />
<meta property="og:description" content="this is the summary" />
<link rel="shortcut icon" href="http://d7.dev/sites/all/themes/epc/favicon.ico" type="image/vnd.microsoft.icon" />
<meta property="og:site_name" content="d7.dev" />
<meta property="og:title" content="Test" />
<link rel="canonical" href="/node/1" />
<link rel="shortlink" href="/node/1" />
<meta name="generator" content="Drupal 7 (http://drupal.org)" />
<meta property="og:type" content="article" />
  <title>Oh title my title! | d7.dev</title>
checker’s picture

I have also still problems with ds and meta tags 7.x-1.0-alpha8.

If a node type uses a display suite layout - a node page uses global meta tags configurations.

Switching off display suite layout for the same node type - a node page uses correctly meta tags configurations and not only globals.

Tested with drupal core theme seven. Any ideas how to debug this?

mezitlab’s picture

@DamienMcKenna: Thank You!
I struggled a lot with metatag + ds combo, but the last dev (7.x-1.0-alpha8+10-dev) release seems work well.

@checker: 7.x-1.0-alpha8 doesn't work with ds module. Try to use the dev release!

damienmckenna’s picture

Assigned: Unassigned » damienmckenna
Status: Fixed » Active

Re-opening this as I'm not satisfied that it Really Is Working(tm).

checker’s picture

Thank you for your feedback DamienMcKenna.
I tried 7.x-1.x-dev 2012-Aug-26. It is the same situation for me described in #69 (with 7.x-1.0-alpha8).

jawi’s picture

same issue here

contenttype with display suite show site wide metatags

jawi’s picture

same issue here

contenttype with display suite show site wide metatags

flocondetoile’s picture

I confirm. I have exactly the same probleme described in #69
With the version 7.x-1.0-alpha8+10-dev

jawi’s picture

So we should use metatags_quick
it works with fields!

http://drupal.org/project/metatags_quick

Nightwalker3000’s picture

Also the same issue here which described in #69
I really dont want to Bug you but is there any News? I'm using open graph to show the Image and description in Facebook and now there always shows the default Image

hans_dampfer’s picture

Subscribing

silkogelman’s picture

Please use the follow button to subscribe
http://drupal.org/node/1306444

gagoo’s picture

Hello,

Same as #69 for me :(

Display Suite and Meta Tags modules are essencials to every drupal 7 website in my opinion !
It would be great if they could work fine together :)

Thank you.

damienmckenna’s picture

Status: Active » Postponed

In my limited testing the patch in #1784896: Overriding meta tags fall back to parent default tag value appears to resolve this, could others please help test the patch from the POV of using DS? Thanks.

damienmckenna’s picture

Issue tags: -meta tag

Removed an unnecessary tag.

checker’s picture

Patch #13 from #1784896: Overriding meta tags fall back to parent default tag value fixed the display suite bug. Tested with current dev.

Nightwalker3000’s picture

Confirm patch #13 in #1784896: Overriding meta tags fall back to parent default tag value works with newest dev version 7.x-1.0-alpha8+13-dev from 1. Oktober.
Thanks

damienmckenna’s picture

Title: Make Metatag work with Display Suite » Make Metatag work OOTB with Display Suite
Status: Postponed » Fixed

I've committed the patch from #1784896, so the next dev version should work correctly. Feel free to re-open if it doesn't work.

damienmckenna’s picture

Status: Fixed » Closed (fixed)

Last night saw the release of 7.x-1.0-beta1, so I'm closing all these "fixed" issues in the interest of tidying up the issue queue. Thank you all for your help getting us to this point!

malc0mn’s picture

#14 works for me as well. What did not work for me, as mentioned by several people, is when you have view mode other than 'full' and still need metatags to display. The problem is in function metatag_field_attach_view_alter():

  if (metatag_entity_supports_metatags($entity_type, $bundle) && $context['view_mode'] == 'full' && _metatag_entity_is_page($entity_type, $context['entity'])) {

There is a check on view_mode here. What I did to get around it is:

  // Get view modes (comma separated string) for which we can show metatags.
  $view_modes = explode(',', variable_get_value('metatag_view_modes'));

  if (metatag_entity_supports_metatags($entity_type, $bundle) && in_array($context['view_mode'], $view_modes) && _metatag_entity_is_page($entity_type, $context['entity'])) {

Even wanted to create a patch to help ppl. overcome this situation until a 'proper' solution is found, but there is no real place to put the settings form where you can alter the viewmodes. Ideally you ad this to the metatag settings and make an exception for this field => extract the view_modes field, unset it and use it in the above situation.

damienmckenna’s picture

@malc0mn: Please open a new issue for supporting multiple view modes, I don't want to clutter this closed issue with other discussions. Thanks.

jfeltkamp’s picture

#14 worked for me.

I had also to disable the option "no extras" in the content-pane properties of my panels content-element.

damienmckenna’s picture

Assigned: damienmckenna » Unassigned
Issue summary: View changes