META Tags PHP Code

Discussion in 'Templates customization' started by searchmaster, Jul 17, 2017.

  1. searchmaster

    searchmaster New Member

    Joined:
    Jul 28, 2016
    Messages:
    15
    I always include the Facebook open graph META information at the top of ALL my pages, and on the new site I am building I am using aMember to control ALL the content, with the application installed in the root.

    The FB open graph tags request titles, URLs and descriptions for each page to be placed in the header of each page. I've been able to easily put together something for the page title and the URL, but not the description. Can someone help me with the correct PHP code to print out just the description META tag that an admin would have filled in for that specific page? Here is what I have so far - and everything works EXCEPT the description code. Thanks in advance for ANY help!

    Code:
    <meta property="og:title" content="<?php p(isset($meta_title) ? $meta_title : $title) ?>" >
    <meta property="og:site_name" content="SITE NAME">
    <meta property="og:url" content="<?= "https://mysite.com".$_SERVER['REQUEST_URI']; ?>" >
    <meta property="og:description" content="<?php p(isset($meta_description) ? $meta_description : $description) ?>" >
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hello,

    I am afraid there is not fancy way to extract content from headMeta view helper but this code should do the job at least:
    PHP:
    <meta property="og:description" content="<?php p(array_reduce($this->headMeta()->getContainer()->getArrayCopy(), function($c$n) { return $n->name == 'description' $n->content $c; })) ?>" />
    I hope it helps.

    Best Regards.
  3. searchmaster

    searchmaster New Member

    Joined:
    Jul 28, 2016
    Messages:
    15
    Thanks SO much Caeser, that definitely did the trick - I very much appreciate your help.

    The Facebook Open Graph inclusions are something of a MUST for anyone building a modern website, and especially for anyone who is trying to use aMember as their main CMS for a small site like I am. With this trick, the only thing missing is the ability to assign an image to each of the individual pages in the same manner.

    I would humbly request that the aMember team consider adding some type of support for open graph META tags within your systems. Obviously you would need to expand on this idea to make it useful for more than just Facebook, but all of the components are already there, you would just need to add an IMAGE option to the META table for each page (in addition to the title, keywords, and descriptions you already have in place) and then make an easy way to access it - or just add the IMAGE option and let customers access the code easily, like you just helped me with. Just an idea to make aMember even better!
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Thank you for your contribution! I definitely will pass your suggestion to our development team.

    Best Regards.

Share This Page