In my last technical post titled Content SEO - Hidden in Plain Sight, I exposed a caveat in the way the title of a content item is auto-crafted by Liferay. Here’s an excerpt from that article, which I hope highlights the problem. If not, I encourage you to give that post a read..
Note that the Title specified is Young Night. But if you look at what got into the page source above, you can see we had: Young Night - Browse Poems - Liferay. The page name and site name seem to get suffixed to the Title.
So, here is how I solved it:
Lunch!
Over at LSNA2016, I hunted down the Content Management Roadmap table and found Julio Camarero crowded by rabid developers bombarding him with all sorts of CMS questions. I took my seat across from him… and waited.
...and waited
...and waited
...AND WAITED!
I eventually spied the door open and shamelessly stuck my foot in. In a blast of what felt like 400 words, I explained the problem as alluded to in my previous post hyperlinked at the top of this article.
Julio nodded and responded with - I paraphrase - “Yeah, there’s a JSP in the asset publisher where we construct the content title in that way. Email me in a couple days.”
I did. He responded. And here it is.
The first order of business is to understand that the below JSP is where the title and subtitle are seeded.
ROOT/html/portlet/asset_publisher/asset_html_metadata.jsp
<%@ include file="/html/portlet/asset_publisher/init.jsp" %><%AssetEntry assetEntry = (AssetEntry)request.getAttribute("view.jsp-assetEntry");AssetRenderer assetRenderer = (AssetRenderer)request.getAttribute("view.jsp-assetRenderer");String title = (String)request.getAttribute("view.jsp-title");if (Validator.isNull(title)) {title = assetRenderer.getTitle(locale);}String summary = StringUtil.shorten(assetRenderer.getSummary(locale), abstractLength);PortalUtil.setPageSubtitle(title, request);PortalUtil.setPageDescription(summary, request);PortalUtil.setPageKeywords(AssetUtil.getAssetKeywords(assetEntry.getClassName(), assetEntry.getClassPK()), request);%>
Now, you can insert a line to set the page title to the empty string.
<%@ include file="/html/portlet/asset_publisher/init.jsp" %> <%AssetEntry assetEntry = (AssetEntry)request.getAttribute("view.jsp-assetEntry");AssetRenderer assetRenderer = (AssetRenderer)request.getAttribute("view.jsp-assetRenderer");String title = (String)request.getAttribute("view.jsp-title");if (Validator.isNull(title)) {title = assetRenderer.getTitle(locale);}String summary = StringUtil.shorten(assetRenderer.getSummary(locale), abstractLength);PortalUtil.setPageTitle("", request);PortalUtil.setPageSubtitle(title, request);PortalUtil.setPageDescription(summary, request);PortalUtil.setPageKeywords(AssetUtil.getAssetKeywords(assetEntry.getClassName(), assetEntry.getClassPK()), request);%>
The problem with the above is that your title eventually changes from:
Young Night - Browse Poems - Liferay
… to
Young Night - - Liferay
Ugh! So, now I needed to figure out where that concatenation happens. I just plain didn't know. After some unsuccessful grepping, I decided to reach out to Julio again, and he graciously shone a light on where this happens. Here are the relevant lines from init.vm of the _unstyled theme.
#if ($pageSubtitle)#set ($the_title = $pageSubtitle + " - " + $the_title)#end
Assuming your theme is based on the _unstyled theme, this value can be overridden by defining an init_custom.vm file and setting $the_title to be the $pageSubtitle alone, i.e.
#set ($the_title = $pageSubtitle)
Now, your title looks like this:
There!
WHAT?! Not satisfied?
I suppose you don’t want the site name to appear either. You find that trailing - Liferay there undesirable?
Keep in mind that the site name (aka company name) may be a good thing to hang on to depending on how your SEO philosophy pans out. I don’t know what the best practice is with respect to that, but if you don’t want it, simply remove the - $company_name variable from the value of the <title/> element in the portal_normal.vm of your theme.
<head><title>$the_title - $company_name</title>……
Tweak $the_title of your content
Fa-la-la-la-la la-la-la-laaa
Find the $company_name, yank it
Fa-la-la-la-la la-la-la-laaa
Have a great November!
FYI a ticket has been opened for the Content SEO fields to be configurable.
https://issues.liferay.com/browse/LPS-68495
...as well as an issue for the problem at hand, here:
https://issues.liferay.com/browse/LPS-68493

