Pavan
Pavan

Reputation: 318

How to add meta tag name = "title" in liferay page programmatically?

I am using liferay 6.0.

I want to add title meta tag (SEO tag) in a liferay page programmatically. liferay has API to add description and keyword meta tags but they don't have any api for title meta tag. Refer : http://www.devatwork.nl/2010/03/seo-optimize-a-liferay-portlet-title-description-keywords/

Is there any way to add custom SEO meta tag via API?

Thanks, Pavan

Upvotes: 2

Views: 3520

Answers (2)

user1965824
user1965824

Reputation: 1

You can do it by adding markup head elements as properties to the PortletResponse.

Here's an example:

Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

Element element = doc.createElement( "meta");

element.setAttribute( "name", "title" );
element.setAttribute( "content", "Your title" );

portletResponse.addProperty( MimeResponse.MARKUP_HEAD_ELEMENT, element );

Upvotes: 0

mvmn
mvmn

Reputation: 4057

You can create custom Theme that would support this. Use theme settings to configure the value. Then in portal_normal.vm add rendering of meta tag using your theme setting value.

Alternatively, you could create a hook for html\common\themes\top_meta.jspf that would render the value. The value itself could be put in theme settings (though that would still require using a custom Theme), or for example in portal-ext.properties (if having a global value is preferable for you). Or you could use custom fields per page or per site - depending on your needs.

Upvotes: 1

Related Questions