How to create metatags for pages resulting of Views module?

Files: 
CommentFileSizeAuthor
#32 metatag-n1804356-32.patch10.74 KBDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]
#31 metatag-n1804356-31.patch0 bytesDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]
#22 metatag-n1804356-22.patch10.76 KBDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]

Comments

Status:Active» Closed (duplicate)

You have to add a token to show each page. This can be done in Global settings. See this issue: http://drupal.org/node/1473422

Status:Closed (duplicate)» Active

Sorry, but your reply does not help me.
What are those Global Settings you're speaking of? from Views module? from Metatags module?
I looked long for each module but could not get a clue.

  • Install the Meta Tags module
  • Enable the Meta Tags module on the modules page
  • Go to Configuration
  • Click on Meta Tags - Configure Meta Tag defaults
  • Click Global
  • Click Edit
  • Add this to your title: [current-page:page-number]
  • Clear your Drupal caches under Configuration - Performance
  • Clear all your browser caches
  • Check your View Source to see the changes
  • If it does not work, make sure you have the latest dev version of Meta Tags installed, not the regular one. It has to be the dev for this to work at this time.
  • Please close this issue when you have found your solution. This is an exact duplicate of the link above.

New update: work is going on today about this issue at http://drupal.org/node/1809652

Be sure to read that, because some changes are happening.

Thanks Couturier for your help.

Problem is that you are speaking only of title metatag.
I'd like to add all the metatags to a view, same as for a node : it means description and keywords metatags. Is not it possible?

Title:Views metatagsViews integration: option to add meta tags within the Views UI

@Sahuni: It depends on what you want to do:

What I'd really like to do is merge Dave's sandbox into the main module.

Component:User interface» Code

Well,
I don't use context module and I think it's too a big module to add. I have less than 10 views.
I'm not use to play with sanboxes and git, so not a welcome solution
in the French forum, someone said to use http://drupal.org/project/views_field. Seems odd.

Perhaps, I'll add metatags with code in preprocess treatment (I did that in D6).

But it would be fine to have a real possibility to have good SEO for views, with help of user interface.

The code here works pretty well, should help until this gets worked on: http://drupal.org/sandbox/davereid/1281614

Git Noob here... i get an empty master branch there... how can i download the source from a branch?

@RollWhiTler: You probably just followed the instructions on the project's main page, right? You need to grab the 7.x-1.x branch:

git clone --recursive --branch 7.x-1.x http://git.drupal.org/sandbox/davereid/1281614.git views_metatags

@DamienMcKenna,
Hmm, this looks very complex to me. Maybe I will wait until it will be implemented to module.

Is there support coming for http://drupal.org/sandbox/davereid/1281614 ?

@aidanlis That project is over a year old, and since then, Views has moved to core for D8. It seems to me that since time is limited for support for Meta Tags itself, it would be hard to find someone to continue working on this project to integrate the same things you can currently do in Meta Tags into Views.

How to create metatags for pages resulting of Views module?

Easiest solution is to create a block view and place block inside regular node. Then set metatags on the node.

and @WiredEscape, what would be the easiest way to do that?

@sahuni Under Structure > Blocks > Configure > Show block on specific pages > Only the listed pages = Add your node URL there for the block

Yes it's a good idea, thanks

Version:7.x-1.0-alpha8» 7.x-1.x-dev
Category:support» feature

http://drupal.org/sandbox/davereid/1281614 is now up to date and will likely either be promoted to a full project or merged as a sub-module here.

I'd definitely vote to add it as a submodule, similar to metatag_context. I also would recommend renaming the module to "metatag_views" to keep the naming consistent with other submodules.

++

Status:Active» Needs review
StatusFileSize
new10.76 KB
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]

Here's Dave's code from the sandbox renamed as metatag_views and provided as a submodule.

Status:Needs review» Reviewed & tested by the community

I've been rolling with the sandbox code for a while now and it works as advertised!

Status:Reviewed & tested by the community» Needs review

This patch needs a bit more testing.

Needs to test:

  • Removing metatag_views.install. The extender should be enabled by default due to 'enabled' => TRUE being set in it's definition.
  • metatag_views_page_alter should possibly use metatag_page_set_metatags()?
  • Should a default configuration for Views be enabled by default?

Hi Dave,
I've revealed a problem: the current code only works with the default configuration, overrides will always be ignored.

The reason is, that the function call to metatag_metatags_view() does not provide a language code inside the $metatags array. It's directly starting with the keyed meta tags. But metatag_metatags_view() is expecting a language code as key in the top level of the array. Otherwise nothing will be found, and the default configuration for Views will be used.

I think, that a solution for this problem would perfectly accompany with fixing the missing translation support (see http://drupal.org/node/1773950)

PS: I should have mentioned that I'm using the latest dev of metatag including the Entity Translation related patch from http://drupal.org/node/1845326#comment-6973542. But when I look into the code of beta2, I can see, that it wouldn't work with that version either

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

I have also around 10 Views generated pages that were lacking META-s. I solved this by using Simple Meta module. This module allows 3 basic tags to be overruled: Title, Description and keywords. I actually only use the first two.

So, now I have 2 META modules working together: the regular Meta Tags module that is used for nodes, and Simple Meta for Views pages. Whenever I need to edit Views META-s, I switch its special tab on, it appears at the left side of the screen, then I navigate to the page, click on the tab, edit it, and Save. After doing so, I disable the tab, as it's a little annoying, even though visible only to administrators.

I am able to replicate the behavior @agoradesign describes.

  1. Create a new view
  2. Override default meta tag settings by checking 'Prevent search engines from indexing this page' box under advanced settings.
  3. Save the view and visit the page
  4. '<meta content="noindex" name="robots">' should render in the page header but does not.

In the interim, Views PHP offers a solution for this issue by way of the 'drupal_add_html_head' function.

  1. Install and enable Views PHP.
  2. Add a 'Global: PHP' element to the View header.
  3. Insert the code below, customized for your use:

<?php
  $element
= array(
   
'#tag' => 'meta',
   
'#attributes' => array(
     
'name' => 'robots',
     
'content' => 'noindex',
    ),
  );
drupal_add_html_head($element, 'robots_noindex');
?>

In the long-term, a reworked patch from #22 #1804356-22: Views integration: option to add meta tags within the Views UI is a better solution; however, the code immediately above will work in the mean time,

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

StatusFileSize
new0 bytes
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]

This fixes the issue that agoradesign mentions in #26 so it's now possible to actually override the values on each View.

StatusFileSize
new10.74 KB
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]

DOH!

Status:Needs review» Fixed

COMMITTED!!! Thanks Dave!!!

All follow-up work should be in new issues.

Status:Fixed» Closed (fixed)

1.0-beta6 is out, so I'm closing this issue in the interest of keeping the issue queue clean.