<p>SEOmatic has some functions that it uses for its controller endpoints for returning metadata for SPAs and the like:</p>

<p><a href="https://nystudio107.com/docs/seomatic/Advanced.html#headless-spa-api" rel="nofollow noreferrer">SEOmatic headless SPA APIs</a></p>

<p>We can leverage these for our own purposes in an Element API endpoint, if for some reason you can't ping the SEOmatic controller via AJAX or use GraphQL to access the data.</p>

<pre class="lang-php prettyprint-override"><code>use nystudio107\seomatic\helpers\Container as ContainerHelper;
use nystudio107\seomatic\models\MetaJsonLdContainer;
use nystudio107\seomatic\models\MetaLinkContainer;
use nystudio107\seomatic\models\MetaScriptContainer;
use nystudio107\seomatic\models\MetaTitleContainer;
use nystudio107\seomatic\models\MetaTagContainer;

...

        $result = ContainerHelper::getContainerArrays(
            [
                MetaTitleContainer::CONTAINER_TYPE,
                MetaTagContainer::CONTAINER_TYPE,
                MetaLinkContainer::CONTAINER_TYPE,
                MetaScriptContainer::CONTAINER_TYPE,
                MetaJsonLdContainer::CONTAINER_TYPE,
            ],
            $uri,
            $siteId,
            true
        );
</code></pre>

<p>You'll get an array of the container information back, and you can do whatever you like with it.</p>

CC BY-SA 4.0
2019-11-05T01:01:58.827Z
2019-11-05T01:01:58.827Z
andrew.welch
<p>How do I get the meta tags used in SEOmatic for a specific entry and returning it through the Element API?</p>

<p>Not sure how the PHP code looks like when using SEOmatic's PHP API.</p>

<php><plugin-elementapi><plugin-seomatic>
How to pull an entry's SEOmatic meta tags with Element API?
# How to pull an entry's SEOmatic meta tags with Element API?

(Asked by: username_0 on 2019-11-04)

How do I get the meta tags used in SEOmatic for a specific entry and returning it through the Element API?

Not sure how the PHP code looks like when using SEOmatic's PHP API.

**Tags:** php, plugin-elementapi, plugin-seomatic

---

## 1 answers

### Answer by username_1 on 2019-11-05. Score: 3 | Accepted answer

SEOmatic has some functions that it uses for its controller endpoints for returning metadata for SPAs and the like:
SEOmatic headless SPA APIs
We can leverage these for our own purposes in an Element API endpoint, if for some reason you can't ping the SEOmatic controller via AJAX or use GraphQL to access the data.
use nystudio107\seomatic\helpers\Container as ContainerHelper;
use nystudio107\seomatic\models\MetaJsonLdContainer;
use nystudio107\seomatic\models\MetaLinkContainer;
use nystudio107\seomatic\models\MetaScriptContainer;
use nystudio107\seomatic\models\MetaTitleContainer;
use nystudio107\seomatic\models\MetaTagContainer;

...

        $result = ContainerHelper::getContainerArrays(
            [
                MetaTitleContainer::CONTAINER_TYPE,
                MetaTagContainer::CONTAINER_TYPE,
                MetaLinkContainer::CONTAINER_TYPE,
                MetaScriptContainer::CONTAINER_TYPE,
                MetaJsonLdContainer::CONTAINER_TYPE,
            ],
            $uri,
            $siteId,
            true
        );

You'll get an array of the container information back, and you can do whatever you like with it.


---

