Filling HTML Meta tags on article pages

The goal of this example is to populate the meta tags on our page with the list of keywords associated with the article as well as the names of the authors.

If you want to optimise the indexing of your site by search engines, you can, for example, include the description of the article, the associated keywords and the name of the authors in special tags, called "meta tags" which are located in the HTML document’s header and not normally visible to casual site visitor.

SPIP enables you to fill out these fields for each page on your site quite automatically, for example, using the article’s description, any keywords associated to that article, as well as the name(s) of the article’s author(s).

Meta tag examples filled by SPIP
Action HTML/SPIP syntax
Page title <title>[(#NOM_SITE_SPIP|textebrut)]</title>
Description [<meta name="Description" content="(#INTRODUCTION|couper{200}|textebrut)" />]
<meta name="Keywords" content="<BOUCLE_keywords(MOTS) {id_article} {","}>[(#TITRE|textebrut)]</BOUCLE_keywords>" />
Authors [<meta name="Author" content="(#LESAUTEURS|textebrut)" />]
Application name <meta name="Generator" content="SPIP[ (#SPIP_VERSION)]" />
Webmaster’s e-mail [<meta name="Reply-to" content="(#EMAIL_WEBMASTER|textebrut)" />]

Do not forget to apply the filter textebrut on the SPIP tags to remove any tags, paragraph marks and spaces that don’t belong here. Also, stay within the limits of the number of characters requires by each meta tag, using the couper filter.

Note here that we’ve used an embedded loop structure to retrieve the keywords based on the current id_article. In addition, we have specified the comma as a separator so that the meta tag contents make sense (including being understood by the search engines).

These meta tags are not essential to the indexing of the site. On the other hand, do not forget the page title, which is still important especially because it identifies each page of your site in the search engine results.

Here is the full example for the article template (to be placed in a ARTICLES loop within the head tags of the page

<title>[(#TITRE|textebrut) - ][(#NOM_SITE_SPIP|textebrut)]</title>
[<meta name="description" content="(#INTRODUCTION|sinon{#DESCRIPTIF_SITE_SPIP}|couper{200}|attribut_html)" />]
<B_keywords><meta name="keywords" content="<BOUCLE_keywords(MOTS) {id_article} {","}>[(#TITRE|attribut_html)]</BOUCLE_keywords>" /></B_keywords>
[<meta name="author" content="(#LESAUTEURS|attribut_html)" />]
<meta name="generator" content="SPIP[ (#SPIP_VERSION)]" />
[<meta name="reply-to" content="(#EMAIL_WEBMASTER|attribut_html)" />]

You can adapt this example to other kinds of elements such as sections, news items, etc.

Author George Published : Updated : 20/04/23

Translations : عربي, català, English, Español, français, italiano, Nederlands, українська