Add to header from a custom page type (not a block)

Permalink
I'd like to add a string of `meta` tags to the `head` based on page attributes for just a particular page type (not all pages on my site).

All documentation I can find relates to the `addHeaderItem` in a block. But how do I do this from a page template?

smeranda
 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi smeranda,

What version of concrete5 are you using?

Here is an example of how it could be done.

1. Let us say you want to put this meta tag on blog_entry page types only.
<meta name="favorite:food:ice_cream" content="">

2. You have an attribute called Favorite Ice Cream with the attribute handle of ice_cream_flavor. The value of ice_cream_flavor should be used as the value for the meta tag content.

3. In your page template include/elements PHP file that has your <head> code (header_top.php or header.php).
Add this:
<?php if ($c->getCollectionTypeHandle() == 'blog_entry' && $c->getCollectionAttributeValue('ice_cream_flavor')) { ?>
    <meta name="favorite:food:ice_cream" content="<?php echo $c->getCollectionAttributeValue('ice_cream_flavor'); ?>">
<?php } ?>

If the page type is equal to blog_entry and the attribute value is true (there is a value set), then the meta tag will be added to the page. The value of $c->getCollectionAttributeValue('ice_cream_flavor') will be echoed as the value for the meta tag content value.

If the user typed in "mint chocolate chip" for the Favorite Ice Cream attribute. The meta tag would be:
<meta name="favorite:food:ice_cream" content="mint chocolate chip">
smeranda replied on at Permalink Reply
smeranda
Thanks! We're on 5.6. This could work well, thanks!
MrKDilkington replied on at Permalink Reply
MrKDilkington
Please report back with your results.
Janks replied on at Permalink Reply
Janks
I have a similar challenge as various jQWidgets css links and javascript references shall be placed in the page header section for multiple single pages containing various jQWidgets.

That means, the first single page jQWidgets require some javascript references, the second single page jQWidgets require some other javascript references, etc.

The theme elemental/elements/header_top.php file can then be updated, and let the various jQWidgets css links and javascript references be inserted based on the current single page.

Is this the only solution however? Or do we have other possible solutions to this?
Pluto replied on at Permalink Reply 1 Attachment
Pluto
Simply go to your dashboard sitemap. Click on the page in which you want meta tag. click on properties menu. Click on custom attribute tab. There you can see Meta Title, Meta Description and Meta Keywords. Click on them which you nedd that will be listed in the selected attribute section. Set the text which you want. and then click on save. That will reflect on your site
smeranda replied on at Permalink Reply
smeranda
True, but that's not scalable given the hundreds of pages with this particular page type. In addition, the meta tags are exporting data already entered into fields (title, thumbnail src, description, etc..).
Pluto replied on at Permalink Reply
Pluto
If you want same meta tags for a page type?