In part 1 of this blog post we discussed how to embed a canonical url and shortlink into the source code of an HTML web page. We also discussed how to avoid impacting SEO with multiple urls for identical content by using the Global Redirect module. In this blog post I’ll describe a way to insert the shortlink onto the web page in a simple and reusable format for most any Content Type in your Drupal website.
The Desired Output We Want to Achieve
In addition to embedding the shortlink and canonical urls within the source of the webpage. We would like to show the shortlink on the page as raw text (not a URL) so that the page can be cited in bibliographies and online citations. By default, Drupal will not do this for us. Our legacy website we’re importing into Drupal 7 as a project I’m working on has such an example:
So we want to mimic this using standard Drupal tools and conventions. Typical Drupal tools we might try to utilize are for example:
- If possible can we make the shortlink text a drupal Field to place within content?
- Do we have to write custom code to access the shortlink value, or perhaps is there a Token we can make use of?
- Do we have to create custom template files to place this shortlink at the bottom of these template files? Or, is there a simpler means to control when/how this content is displayed?
The Recipe to Show ShortLink on Content Types
Lately, I’ve been making heavy use of the Display Suite module. I’ve covered DS in the past here at Arvixe and this is another case where it makes our life easier. In a nutshell, we can:
- Create a pseudo field using Display Suite, which uses a Token to make the shortlink into a Drupal Field which is available to any Drupal content type (Node).
This is exactly what we want and it’s relatively simple to setup after you have installed Display Suite and the Token modules.
By creating a custom DS field, this field may be available to any Node (Content Type) we create in the system. So we can create this once and reference it whenever in the system — now with the existing Content Types. Or, 2 years from now when additional content types have been added into the system.
The configuration for our DS field is as follows. Note it is limited just to Nodes and it makes use of some tokens.
But, what tokens are we using here:
- [metatag:shortlink] is the short url link to our content in the format of /node/NID in this case for a Drupal website.
- [node:title] is the title of the piece of content the visitor is viewing.
These pieces of information allow for a valid citation to be referenced by 3rd party researchers and the media when referencing our website.
Next, we simply assure that the view_mode of the content using Display Suite has embedded the Citation field into the page somewhere, ideally at the bottom of the page:
Note, that the label of the psuedo field becomes the Label of the field in Drupal … and that there’s no need to add colons at the end of our label by hand — Drupal takes care of that formatting for us.
If we visit the page now we will see the desired output:
Looking for quality web hosting? Look no further than Arvixe Web Hosting!