Optimize Ghost for SEO - Page Title
The Ghost blogging platform does not actually have plugins (and maybe will always be this way). A thing I missing after migration is the SEO optimization for any blog post... so I stated making it by myself.
First step: change page title to respect SEO "rules". The title of any post page should also have the blog name suffix:
<title>Post title | Blog name<title>
To accomplish this in Ghost you can proceed into two different ways:
Personalise the default.hbs file in your theme
<title>{{meta_title}} | {{@blog.title}}</title>
Change the Ghost core to provides the meta_title variable with the correct value, allowing you to change theme without losing SEO customisations. Edit the file core/server/helpers/index.js around the line 395. Following the complete code of my meta_title function:
coreHelpers.meta_title = function (options) {
/*jslint unparam:true*/
var title = "",
blog;
if (_.isString(this.relativeUrl)) {
if (!this.relativeUrl || this.relativeUrl === '/' || this.relativeUrl === '' || this.relativeUrl.match(/\/page/)) {
blog = config.theme();
title = blog.title;
} else if (this.post) {
blog = config.theme();
title = this.post.title + ' | ' + blog.title;
}
}
return filters.doFilter('meta_title', title).then(function (title) {
title = title || "";
return new hbs.handlebars.SafeString(title.trim());
});
};
In bold the code I changed.
Restart your NodeJS server and enjoy your first SEO optimization.