HTML Meta Tag Generator






1.82/5 (9 votes)
Jan 15, 2007
1 min read

28523

218
Visual HTML Meta Tag Generator
Introduction
Because of how often I need to generate Meta Tags for my web pages, and how difficult it is to remember all meta attributes (description, author... etc) I decided to write an application (small one) to do this job for me every time I need (create a new page for my sites).
This set of meta tags is not complete, a meta tag can have many different attributes, but this program i created is only for the ones i use most often(for full list of attributes: ask Google!)
I will generate the tags with only these attributes:
title, description, keywords, author, distribution and revisit
Let's start to create an Object - MetaTagObj to store all the information we need inside.
The code for MetaTagObj class is:
using System;
namespace MetaTagGenerator
{
class MetaTagObj
{
private string title;
private string desc;
private string keys;
private string author;
private string distribution;
private string revisit;
public string Title
{
get { return title; }
set { title = value.Trim(); }
}
public string Desc
{
get { return desc; }
set { desc = value.Trim(); }
}
public string Keys
{
get { return keys; }
set { keys = value.Trim(); }
}
public string Author
{
get { return author; }
set { author = value.Trim(); }
}
public string Distribution
{
get { return distribution; }
set
{
if (value.Trim() == "")
{
distribution = "Global"; //default value
return;
}
distribution = value.Trim();
}
}
public string Revisit
{
get { return revisit + " Days"; }
set
{
if (value.Trim() == "")
{
revisit = "10";
return;
}
revisit = value.Trim();
}
}
public MetaTagObj(): this("Title here", "Description Here", "", "", "", "")
{
}
public MetaTagObj(string title, string desc, string keys, string author, string distribution, string revisit)
{
Title = title;
Desc = desc;
Keys = keys;
Author = author;
Distribution = distribution;
Revisit = revisit;
}
public override string ToString()
{
string MetaTag = "";
MetaTag += "<title>"+ Title + "</title>" + Environment.NewLine;
MetaTag += "<meta name=\"description\" content=\"" + Desc + "\" />" + Environment.NewLine;
MetaTag += "<meta name=\"keywords\" content=\"" + Keys + "\" />" + Environment.NewLine;
MetaTag += "<meta name=\"author\" content=\"" + Author + "\" />" + Environment.NewLine;
MetaTag += "<meta name=\"distribution\" content=\"" + Distribution + "\" />" + Environment.NewLine;
MetaTag += "<meta name=\"revisit-after\" content=\"" + Revisit + "\" />" + Environment.NewLine;
return MetaTag;
}
}
}
In this class I do all the work for Meta tag creation (also, I include the TITLE tag here). This class is simple, two constructors, one with parameters, one empty. Some properties for private variables, with some default values (some of them).The main form contains (screen capture on top of page) few TextBoxes, where the user can introduce data (values for specific attribute.), 3 buttons (Generate, Copy to Clipboard and About) and a TextBox (ReadOnly) for generated code!
. To use this program, you need to fill all the textboxes you want and to press the Generate Button. After this just Copy/Paste the code inside your HTML doc, on HEAD section.
Enjoy!