onedesign / Craft-OneSeo

SEO Plugin for Craft projects
0 stars 0 forks source link

Add template functions for manipulating meta title, description, image. #10

Open cmalven opened 9 years ago

cmalven commented 9 years ago

It isn't uncommon to want to set a custom title or description for the page from within the template.

E.g.

{% set metaImage = entry.propertyImages.first %}

or…

{% set description = entry.summary %}

It's pretty easy to do this with vars, as shown above, because those vars can be read by the parent layout. But ideally we'd be able to do something like…

Descriptions and Images

{% craft.odcSeo.setDescription(entry.description) %}
{% craft.odcSeo.setImage(entry.image.getUrl(transforms.opengraph)) %}

Titles

Titles are a little bit trickier, because ideally we could set the title to be a set of paths, e.g.

{% craft.odcSeo.setTitle(entry.title) %}
<!-- Results in 'My Title – My Site Name' -->

or

{% craft.odcSeo.setTitle([entry.title, 'Properties']) %}
<!-- Results in 'My Title – Properties – My Site Name' -->