budry/php-open-graph

Simple object based Open Graph generator

v1.0.0 2022-04-04 12:56 UTC

This package is auto-updated.

Last update: 2024-12-10 17:03:10 UTC


README

Simple object generator for open graph protocol. Full implementation of this specification

Installation

The best way to install budry/php-open-grap is using Composer

$ composer require budry/php-open-grap

How to use

Create open graph instance and configure

$image = new \Budry\OpenGraph\Objects\Image("https://example.com/image.jpg");
$openGraph = new \Budry\OpenGraph\OpenGraph("Page title", "Page URL", $image);

$article = new \Budry\OpenGraph\Types\Article();
$article->setExpirationDate(new DateTimeImmutable("2022-03-12 12:23:24"))
    ->setModifiedDate(new DateTimeImmutable())
    ->setPublishedDate(new DateTimeImmutable())
    ->setSection("SCI-FI")
$openGraph->setType($article);

foreach ($openGraph->getFields() as $field) {
    echo '<meta property="' . $field->getName() . '" content="' . $field->getContent() . '">'
}