Extension:WikiSEO

From mediawiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
WikiSEO
Release status: stable
Implementation Parser function
Description Allows to add common meta elements as part of Search Engine Optimization (SEO)
Author(s) Octfxtalk
Latest version 2.6.5 (2021-03-24)
MediaWiki 1.35+
PHP 7.2+
Composer octfx/wiki-seo
License GNU General Public License 2.0 or later
Download
  • $wgFacebookAdmins
  • $wgPinterestSiteVerificationKey
  • $wgMetadataGenerators
  • $wgGoogleSiteVerificationKey
  • $wgFacebookAppId
  • $wgBingSiteVerificationKey
  • $wgTwitterCardType
  • $wgYandexSiteVerificationKey
  • $wgWikiSeoTryCleanAutoDescription
  • $wgWikiSeoDefaultImage
  • $wgNortonSiteVerificationKey
  • $wgTwitterSiteHandle
  • $wgNaverSiteVerificationKey
  • $wgWikiSeoEnableAutoDescription
  • $wgWikiSeoNoindexPageTitles
  • $wgAlexaSiteVerificationKey
  • $wgWikiSeoDisableLogoFallbackImage
  • $wgWikiSeoDefaultLanguage
Translate the WikiSEO extension if it is available at translatewiki.net

Check usage and version matrix.

The WikiSEO extension allows you to replace, append or prepend the HTML title tag content. It also allows you to add common SEO (Search Engine Optimization) meta elements such as "keywords" and "description".

A working JobQueue is absolutely required for this extension to function.

Version 2.0 is not a drop-in replacement for v1.2.2 (the last version before this fork).
Version 2.3.1 fixes a bug in the generated schema.org search action url. Please update to the newest version of this extension.
Version 2.6.2 and onward requires MediaWiki 1.35.0. You can find the last version supporting =<1.34.0 on branch REL1_34.

Installation[edit]


Usage[edit]

The extension can be used via the {{#seo}} parser function or in Lua modules by using mw.ext.seo.set(). It accepts the following named parameters in any order.

Globally supported parameter names
Name Default Description Example Supported Generators
title (empty) The title you want to appear in the html title tag. Will also be used for OpenGraph, Schema.org and Twitter metadata.
{{#seo:|title=This is the title of the page}}
All
title_mode replace Set to append, prepend, or replace (default) to define how the title will be amended. Further examples can be found here.
{{#seo:|title=This replaces the Title of the Page|title_mode=replace}}
All
title_separator - The separator in case title_mode was set to append or prepend.
{{#seo:|title=This gets prepended to the page name separated by the separator|title_mode=prepend|title_separator=<<}}
All
keywords (empty) A comma separated list of keywords describing the page content. Will also be used for OpenGraph, Schema.org and Twitter metadata.
{{#seo:|keywords=Apple, Pears, Oranges}}
All
description (empty) A short text describing the page topic. Will also be used for OpenGraph, Schema.org and Twitter metadata.
{{#seo:|description=This page contains information about...}}
All


Supported parameter names by the Metatag generator
Name Default Description Example Supported Generators
robots (empty) Controls the behavior of search engine crawling and indexing
{{#seo:|robots=noindex, nofollow}}
Metatag
googlebot (empty) Controls the behavior of the google crawler
{{#seo:|googlebot=noindex, nofollow}}
Metatag
hreflang_xx-xx (empty) Adds <link rel="alternate" href="url" hreflang="xx-xx"> elements
{{#seo:|hreflang_de-de=https://example.com}}
Metatag


Supported parameter names by the OpenGraph / Twitter generator
Name Default Description Example Supported Generators
type (empty) The type of your object, e.g., "video.movie". Depending on the type you specify, other properties may also be required.
{{#seo:|type=website}}
OpenGraph / Twitter
image (empty) An image URL which should represent your object within the graph.
The extension will automatically add the right image url, width and height if an image name is set as the parameter. Example image = Local_file_to_use.png.
Alternatively a full url to an image can be used, image_width and image_height will then have to be set manually.
If no parameter is set, the extension will use $wgLogo as a fallback or the local file set through $wgWikiSeoDefaultImage.
{{#seo:|image=Local_File.png}}
OpenGraph / Twitter
image_width (empty) The image width in px. (Automatically set if an image name is set in image)
{{#seo:|image_width=420}}
OpenGraph / Twitter
image_height (empty) The image height in px. (Automatically set if an image name is set in image)
{{#seo:|image_height=69}}
OpenGraph / Twitter
image_alt (empty) A short sentence describing the image
{{#seo:|image_alt=A picture showing an orange cat.}}
OpenGraph / Twitter
locale (empty) The locale these tags are marked up in. Of the format language_TERRITORY.
{{#seo:|locale=en-US}}
OpenGraph / Twitter
site_name (empty) If your object is part of a larger web site, the name which should be displayed for the overall site. e.g., "IMDb".
{{#seo:|site_name=WMF}}
OpenGraph / Twitter


Supported parameter names by the OpenGraph with type=article [1]
Name Default Description Example Supported Generators
author (empty) Writers of the article.
{{#seo:|author=Jon Doe}}
OpenGraph (article)
section (empty) A high-level section name. E.g. Technology
{{#seo:|section=Technology}}
OpenGraph (article)
published_time (empty) When the article was first published. ISO 8601 Format.
{{#seo:|published_time=01-01-2012}}
OpenGraph (article)


Supported parameter names by the Twitter generator (see OpenGraph Tags)[2]
Name Default Description Example Supported Generators
twitter_site (empty) If you did not set a global site name through $wgTwitterSiteHandle, you can set a site handle per page. If a global site handle is set this key will be ignored.
{{#seo:|twitter_site=MediaWiki}}
Twitter


Supported parameter names by the Citation generator[3]
Name Default Description Example Supported Generators
citation_type ScholarlyArticle Used in @graph @type
{{#seo:|citation_type=MedicalScholarlyArticle}}
Citation
citation_name (empty) Name of the Publication
{{#seo:|citation_name=Cataloging & Classification Quarterly}}
Citation
citation_headline (empty) Headline of the article.
{{#seo:|citation_headline=Works in Cataloging}}
Citation
citation_date_published (empty) Date of first broadcast/publication.
{{#seo:|citation_date_published=2012-01-01}}
Citation
citation_date_created (empty) The date on which the CreativeWork was created or the item was added to a DataFeed.
{{#seo:|citation_date_created=2012-01-01}}
Citation
citation_page_start (empty) The page on which the work starts; for example "135" or "xiii".
{{#seo:|citation_page_start=135}}
Citation
citation_doi (empty) URL of a reference Web page that unambiguously indicates the item's identity. E.g. the URL of the item's Wikipedia page, Wikidata entry, or official website.
{{#seo:|citation_doi=http://dx.doi.org/10.1038/nphys1170}}
Citation
citation_author (empty) One or more authors separated by ';'
{{#seo:|citation_firstpage=Doe, John; Bar, Foo}}
Citation
citation_publisher (empty) Name of the publisher
{{#seo:|citation_journal_title=Elsevir}}
Citation
citation_license (empty) A license document that applies to this content, typically indicated by URL.
{{#seo:|citation_license=link}}
Citation
citation_volume (empty) Volume number
{{#seo:|citation_volume=50}}
Citation
keywords (empty) Article Keywords
{{#seo:|citation_keywords=Keyword a; Keyword b; ...}}
All
description (empty) A description of the item.
{{#seo:|description=An article about cataloging}}
All

Do note that the Citation generator is not activated by default! To activate the generator add the following snippet to LocalSettings.php:

$wgMetadataGenerators[] = "Citation";

Examples[edit]

Adding static values[edit]

{{#seo:
|title=Your page title
|title_mode=append
|keywords=these,are,your,keywords
|description=Your meta description
|image=Uploaded_file.png
|image_alt=Wiki Logo
}}

Adding dynamic values[edit]

If you need to include variables or templates you should use the parser function to ensure they are properly parsed. This allows you to use Cargo or Semantic MediaWiki, with Page Forms, for data entry, or for programmatic creation of a page title from existing variables or content...

{{#seo:
 |title={{#if: {{{page_title|}}} | {{{page_title}}} | Welcome to WikiSEO}}
 |title_mode={{{title_mode|}}}
 |keywords={{{keywords|}}}
 |description={{{description|}}}
 |published_time={{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}
}}
{{#seo:
 |title_mode=append
 |title=Example SEO Wiki
 |keywords=WikiSEO, SEO, MediaWiki
 |description=An example description for this wiki
 |image=Wiki_Logo.png
 |image_alt=Wiki Logo
 |site_name=Example SEO Wiki
 |locale=en_EN
 |type=website
 |modified_time={{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}
 |published_time=2020-11-01
}}

Usage in lua modules[edit]

-- Module:SEO
local seo = {}

--[[
argTable format:
{
  title_mode = 'append',
  title = 'Example Seo Wiki',
  keywords = 'WikiSEO, SEO, MediaWiki',
  -- ...
}
]]--
function seo.set( argTable )
  mw.ext.seo.set( argTable )
end

function seo.setStatic()
  mw.ext.seo.set{
    title_mode = 'append',
    title = 'Example Seo Wiki',
    keywords = 'WikiSEO, SEO, MediaWiki',  
  }
end

return seo

The module would now be callable as {{#invoke:SEO|set|title=ExampleTitle|keywords=WikiSEO, SEO, MediaWiki}} or {{#invoke:SEO|setStatic}}.

Hreflang Attributes[edit]

{{#seo:
 |hreflang_de-de=https://example.de/page
 |hreflang_nl-nl=https://example.nl/page-nl
 |hreflang_en-us=https://website.com/
}}

Will generate the following ‎<link> elements:

<link rel="alternate" href="https://example.de/page" hreflang="de-de">
<link rel="alternate" href="https://example.nl/page-nl" hreflang="nl-nl">
<link rel="alternate" href="https://website.com/" hreflang="en-us">

Title Modes[edit]

Example: Page with title Example Page

Append[edit]

{{#seo:
 |title_mode=append
 |title=Appended Title
}}

HTML Title result: Example Page - Appended Title

Prepend[edit]

{{#seo:
 |title_mode=prepend
 |title=Prepended Title
}}

HTML Title result: Prepended Title - Example Page

Prepend (changed separator)[edit]

{{#seo:
 |title_mode=prepend
 |title=Prepended Title
 |title_separator= >> 
}}

HTML Title result: Prepended Title >> Example Page

Replace (default)[edit]

{{#seo:
 |title_mode=replace
 |title=Replaced Title
}}

HTML Title result: Replaced Title

Maintenance Script[edit]

WikiSEO provides a maintenance script to generate descriptions for specified pages. This script requires Extension:TextExtracts to be installed and active. The script will only generate descriptions for pages that don't have a description property set in the page properties table.

You can force the generation using the --force flag, this will overwrite any description already present.

A list of namespace ids needs to be given in order for the script to work:

# Run only in main namespace
php maintenance/GenerateDescription.php 0

# Run only in main namespace and overwrite existing descriptions
php maintenance/GenerateDescription.php --force 0

# Run in namespace 1234, overwrite descriptions and remove dangling sentences
php maintenance/GenerateDescription.php --force --cleanSentence 1234

Configuration[edit]

The following variables are in use by this extension.

$wgWikiSeoDefaultImage[edit]

Set a default image to use if no image is set on the site. If this variable is not set the site's logo will be used.

Usage: $wgWikiSeoDefaultImage= 'Localfile.jpg';.

$wgGoogleSiteVerificationKey[edit]

Setting this variable will add a <meta name="google-site-verification" content="CODE"> tag to every page.

Usage: $wgGoogleSiteVerificationKey = 'CODE';. See [4] for more information.

$wgBingSiteVerificationKey[edit]

Setting this variable will add a <meta name="msvalidate.01" content="CODE"> tag to every page.

Usage: $wgBingSiteVerificationKey= 'CODE';. See [5] for more information.

$wgFacebookAppID[edit]

Setting this variable will add a <meta property="fb:app_id" content="ID"> tag to every page.

Usage: $wgFacebookAppID= 'App_ID';.

$wgFacebookAdmins[edit]

Setting this variable will add a <meta property="fb:admins" content="ID1,ID2,..."> tag to every page.

Usage: $wgFacebookAdmins= 'ID1,ID2,...';.

$wgYandexSiteVerificationKey[edit]

Setting this variable will add a <meta name="yandex-verification" content="CODE"> tag to every page.

Usage: $wgYandexSiteVerificationKey= 'CODE';. See [6] for more information.

$wgAlexaSiteVerificationKey[edit]

Setting this variable will add a <meta name="alexaVerifyID" content="CODE"> tag to every page.

Usage: $wgAlexaSiteVerificationKey= 'CODE';. See [7] for more information.

$wgPinterestSiteVerificationKey[edit]

Setting this variable will add a <meta name="p:domain_verify" content="CODE"> tag to every page.

Usage: $wgPinterestSiteVerificationKey= 'CODE';. See [8] for more information.

$wgNortonSiteVerificationKey[edit]

Setting this variable will add a <meta name="norton-safeweb-site-verification" content="CODE"> tag to every page.

Usage: $wgNortonSiteVerificationKey= 'CODE';. See [9] for more information.

$wgNaverSiteVerificationKey[edit]

Setting this variable will add a <meta name="naver-site-verification" content="CODE"> tag to every page.

Usage: $wgNaverSiteVerificationKey = 'CODE';. See [10] for more information.

$wgTwitterSiteHandle[edit]

Only used when Twitter generator is loaded.

Setting this variable will add a <meta property="twitter:site" content="@SITE_HANDLE"> tag to every page.

Usage: $wgTwitterSiteHandle = '@SITE_HANDLE';.

$wgMetadataGenerators[edit]

Array containing the metadata generator names to load.

Default: ["OpenGraph", "Twitter", "SchemaOrg"].

If you only want to change the page title and add 'description', 'keywords', 'robots' tags set $wgMetadataGenerators = [];

$wgWikiSeoDisableLogoFallbackImage[edit]

Disable setting $wgLogo as a fallback image if no image for a page was set.

$wgTwitterCardType[edit]

Defaults to `summary_large_image` for the twitter card type.

Usage: $wgTwitterCardType = 'summary';

$wgWikiSeoNoindexPageTitles[edit]

An array of page titles where a 'noindex' robot tag should be added. Usage: $wgWikiSeoNoindexPageTitles = [ 'Custom_Title', 'Main_Page' ];

$wgWikiSeoDefaultLanguage[edit]

A default language code with area to generate a <link rel="alternate" href="current Url" hreflang="xx-xx"> for.

Usage: $wgWikiSeoDefaultLanguage = 'de-de';

$wgWikiSeoEnableAutoDescription[edit]

If no description was given in the parser function, a short description from Extension:TextExtracts will be requested. A description will only be set, if the page is edited and saved. Alternatively the maintenance script GenerateDescription can be run from the extension folder.

$wgWikiSeoTryCleanAutoDescription[edit]

Tries to remove dangling sentences from the description provided by TextExtracts. This will remove the last sentence not ending in a '.', and will result in descriptions shorter than 160 characters.


Migrating from v1.2.2 to to v2.x[edit]

Removed tags[edit]

  • DC.date.created
  • DC.date.issued
  • google
  • name
  • og:title (automatically set)
  • og:url (automatically set)
  • twitter:card (automatically set)
  • twitter:creator
  • twitter:domain
  • article:modified_time / og:updated_time (automatically set)

Removed aliases[edit]

  • metakeywords / metak
use keywords instead
  • metadescription / metad
use description instead
  • titlemode / title mode
use title_mode instead

Changed argument names[edit]

  • article:author -> author
  • article:section -> section
  • article:tag -> keywords
  • article:published_time -> published_time
  • og:image / twitter:image:src -> image
  • og:image:width -> image_width
  • og:image:height -> image_height
  • og:locale -> locale
  • og:site_name -> site_name
  • og:title -> title
  • og:type -> type
  • twitter:description -> description

Known Issues[edit]

Extension:PageImages will add an og:image tag if an image is found on the page. If another image was set using WikiSEO, both og:image will be added to the page.

Notes[edit]

This extension is not a drop-in replacement for the previous version of this extension from tinymighty/wiki-seo.

If you only want to override the display title on pages (not append words to it), you might also look at the DISPLAYTITLE tag in combination with the Manual:$wgAllowDisplayTitle and Manual:$wgRestrictDisplayTitle settings.

schema.org[edit]

The SchemaOrg generator will set a SearchAction property based on Special:Search.[11]

The properties publisher and author will be set to Organization with the name set to the content of $wgSitename.

dateModified will be automatically set by fetching the latest revision timestamp. If no published_time is set, datePublished will be set to the latest revision timestamp.

OpenGraph[edit]

article:modified_time will be automatically set by fetching the latest revision timestamp. If no published_time is set, article:published_time will be set to the latest revision timestamp.

Integration[edit]

WikiSEO will use descriptions provided by Extension:Description2.