github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

kpumuk / meta-tags

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 58
    • 4
  • Source
  • Commits
  • Network (4)
  • Issues (0)
  • Downloads (2)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (2)
    • v1.1.1
    • v1.1.0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Search Engine Optimization (SEO) plugin for Ruby on Rails applications. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Fixed bug when title is set through Array, and :lowercase is true 
kpumuk (author)
Sat Nov 21 09:07:37 -0800 2009
commit  8f0df45909569fc6265c09a185c05a445b1efa48
tree    2d720719f3b4cd2f59b4aa73206b2b5822b348c1
parent  f50979e6bf7bdfb77485e56b01312bacb9969462
meta-tags /
name age
history
message
file .gitignore Sat Nov 21 02:46:36 -0800 2009 Moved documentation to Yard [kpumuk]
file MIT-LICENSE Wed Oct 08 07:55:58 -0700 2008 Fixed plugin author in MIT-LICENSE [kpumuk]
file README.rdoc Sat Nov 21 02:46:55 -0800 2009 Added specs for canonical URL generator [kpumuk]
file Rakefile Sat Nov 21 08:44:27 -0800 2009 Tuned Yard documentation of helpers [kpumuk]
file VERSION.yml Sat Nov 21 02:47:13 -0800 2009 Version bump to 1.1.1 [kpumuk]
file init.rb Thu Nov 05 03:00:29 -0800 2009 Gemified plugin [kpumuk]
directory lib/ Sat Nov 21 09:07:37 -0800 2009 Fixed bug when title is set through Array, and ... [kpumuk]
file meta-tags.gemspec Sat Nov 21 02:47:20 -0800 2009 Regenerated gemspec for version 1.1.1 [kpumuk]
directory spec/ Sat Nov 21 09:07:37 -0800 2009 Fixed bug when title is set through Array, and ... [kpumuk]
README.rdoc

MetaTags

Search Engine Optimization (SEO) plugin for Ruby on Rails applications.

Installation

There are two options when approaching meta-tags installation:

  • using the gem (recommended)
  • install as a Rails plugin

To install as a gem, add this to your environment.rb:

  config.gem 'meta-tags', :lib => 'meta_tags', :source => 'http://gemcutter.org'

And then run the command:

  sudo rake gems:install

To install meta-tags as a Rails plugin use this:

  script/plugin install git://github.com/kpumuk/meta-tags.git

Titles

Page titles are very important for Search engines. The titles in the browser are displayed in the title bar. The search engines would look at the this title bar to determine what the page is all about.

  <title>Some Page Title</title>
  <title>Page Title | Site Title</title>

Recommended title tag length: up to 70 characters, 10 words.

Description

Description tags are called meta tags as they are not displayed by the browsers as that of titles. But these descriptions may be displayed by some search engines. They are used to describe the contents of a page in 2 or 3 sentences.

  <meta name="description" content="All text about keywords, other keywords" />

Recommended description tag length: up to 160 characters.

Keywords

Meta keywords tag are used to place your keywords that you think a surfer would search in Search engines. Repeating keywords unnecessarily would be considered spam and you may get permanently banned from SERP’s

  <meta name="keywords" content="keyword1, keyword2, keyword3" />

Recommended keywords tag length: up to 255 characters, 20 words.

Noindex

By using the noindex meta tag, you can signal to search engines to not include specific pages in their indexes.

  <meta name="robots" content="noindex" />
  <meta name="googlebot" content="noindex" />

This is useful for pages like login, password reset, privacy policy, etc.

Further reading:

  • Blocking Google www.google.com/support/webmasters/bin/answer.py?hl=en&answer=93708
  • Using meta tags to block access to your site www.google.com/support/webmasters/bin/answer.py?hl=en&answer=93710

Nofollow

Nofollow meta tag tells a search engine not to follow the links on a specific page. It’s entirely likely that a robot might find the same links on some other page without a nofollow (perhaps on some other site), and so still arrives at your undesired page.

  <meta name="robots" content="nofollow" />
  <meta name="googlebot" content="nofollow" />

Further reading:

  • About rel="nofollow" www.google.com/support/webmasters/bin/answer.py?answer=96569
  • Meta tags www.google.com/support/webmasters/bin/answer.py?hl=en&answer=79812

Canonical URL

Canonical link element tells a search engine what is the canonical or main URL for a content which have multiple URLs. The search engine will always return that URL, and link popularity and authority will be applied to that URL.

  <link rel="canonical" href="http://yoursite.com/canonical/url" />

Further reading:

  • About rel="canonical" www.google.com/support/webmasters/bin/answer.py?hl=en&answer=139394
  • Canonicalization www.google.com/support/webmasters/bin/answer.py?hl=en&answer=139066

MetaTags Usage

First, add this code to your main layout:

  <head>
    <%= display_meta_tags :site => 'My website' %>
  </head>

Then, to set the page title, add this to each of your views (see below for other options):

  <h1><%= title 'My page title' %></h1>

When views are rendered, the page title will be included in the right spots:

  <head>
    <title>My website | My page title</title>
  </head>
  <body>
    <h1>My page title</h1>
  </body>

You can find allowed options for display_meta_tags method below.

Using MetaTags in controller

You can define following instance variables:

  @page_title = 'Member Login'
  @page_description = 'Member login page.'
  @page_keywords = 'Site, Login, Members'

Also you could use set_meta_tags method to define all meta tags simultaneously:

  set_meta_tags :title => 'Member Login',
                :description => 'Member login page.',
                :keywords => 'Site, Login, Members'

You can find allowed options for set_meta_tags method below.

Using MetaTags in view

To set meta tags you can use following methods:

  <% title 'Member Login' %>
  <% description 'Member login page.' %>
  <% keywords 'Member login page.' %>

Also there is set_meta_tags method exists:

  <% set_meta_tags :title => 'Member Login',
                   :description => 'Member login page.',
                   :keywords => 'Site, Login, Members' %>

The title methods returns title itself, so you can use it to show the title somewhere on the page:

  <h1><%= title 'Member Login' %></h1>

If you want to set the title and display another text, use this:

  <h1><%= title 'Member Login', 'Here you can login to the site:' %></h1>

Allowed options for display_meta_tags and set_meta_tags methods

Use these options to customize the title format:

  • :site — site title;
  • :title — page title;
  • :description — page description;
  • :keywords — page keywords;
  • :prefix — text between site name and separator;
  • :separator — text used to separate website name from page title;
  • :suffix — text between separator and page title;
  • :lowercase — when true, the page name will be lowercase;
  • :reverse — when true, the page and site names will be reversed;
  • :noindex — add noindex meta tag; when true, ‘robots’ will be used, otherwise the string will be used;
  • :nofollow — add nofollow meta tag; when true, ‘robots’ will be used, otherwise the string will be used;
  • :canonical — add canonical link tag.

And here are a few examples to give you ideas.

  <%= title :separator => "&mdash;" %>
  <%= title :prefix => false, :separator => ":" %>
  <%= title :lowercase => true %>
  <%= title :reverse => true, :prefix => false %>

Allowed values

You can specify title as a string or array:

  set_meta_tags :title => ['part1', 'part2'], :site => 'site'
  # site | part1 | part2
  set_meta_tags :title => ['part1', 'part2'], :reverse => true, :site => 'site'
  # part2 | part1 | site

Keywords can be passed as string of comma-separated values, or as an array:

  set_meta_tags :keywords => ['tag1', 'tag2']
  # tag1, tag2

Description is a string (HTML will be stripped from output string).

Alternatives

There are several plugins influenced me to create this one:

  • Headliner: github.com/mokolabs/headliner
  • meta_on_rals: github.com/ashchan/meta_on_rails

Credits

  • Dmytro Shteflyuk (author) <kpumuk@kpumuk.info> kpumuk.info
  • Morgan Roderick (contributor) <morgan@roderick.dk> roderick.dk
  • Sergio Cambra (contributor) <sergio@entrecables.com>
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server