META Tags for Expression Engine Template/Index Pages

I am quite new to Expression Engine, and although its quite flexible it does have it’s shortcomings.

One of the main issues I can see with it is its inability to manage META information. The in-built way would be to create a Channel Field for each Channel so when you publish data you can add in the META information and then display in in the template or header file. BUT if you have many channels, you need different names for each of these and it becomes a lot of fields to manage in conditional statements in the template. You cannot add fields to the main template index file either (e.g. a blog list).

I guess the above reasons is why so many forums online show data being embedded in the template files themselves. Well, although EE may be a great system, this is a massive NO NO for content managed websites. All information like this must be accessible in the CMS by the website owners who are likely not to have HTML experience.

So I installed SEO Lite (https://devot-ee.com/add-ons/seolite).

This works very well on a per page basis (.e.g. an about us, or actual blog page). Because it adds the META fields to the entry for the page.

But this too will not allow an individual template index page to be managed. It seems these template index pages in EE are quite hard to add your own data to.
So I have combined Global Variables with SEO Lite and now have the perfect CMS managed META data.

The following code first checks is a page exists, e.g. blog/blog_post and take META info from there or use the default. If we are not on an individual page, but a template/index file which we don’t have data for (e.g. blog listing).

The second IF statement takes the segment name from the URL and prepends it to some text such as ‘_meta_title’. What this produces is a call to a global variable based on the segment name, e.g. ‘blog_meta_title’. All you need to do is then create the Global Variables based on the segment name.

The last IF statement is for the home page, and will get the META info you add in the Home page.

{if segment_2 != ''}
{exp:seo_lite use_last_segment="yes" friendly_segments="y" default_title='' default_keywords='' default_description='' }
{/if}
{if segment_1 != '' &&  segment_2 == ''}
{exp:seo_lite use_last_segment="yes" friendly_segments="y" default_title='' default_keywords='' default_description='' }
{/if}
{if segment_1 == '' &&  segment_2 == ''}
{exp:seo_lite url_title='home' default_keywords='' default_description='' }
{/if}

Further work I would like to do is if the global variables do not exist, then to show the default SEO Lite content.