SocialMeta
in package
Management of social meta data tags, such as Facebook OpenGraph and Twitter Cards
Table of Contents
Properties
- $meta_name : mixed
- Tags of the form <meta name=":key" content=":val">
- $meta_property : mixed
- Tags of the form <meta property=":key" content=":val">
Methods
- get() : array<string|int, mixed>
- hasTitle() : bool
- Has a page title been set?
- render() : mixed
- Render the social metadata
- setDescription() : mixed
- Set a short (up to two sentence) description for this page
- setImage() : mixed
- Set the image for this page - should be unique to this page; not shared across the site
- setOpenGraphDate() : mixed
- Set a custom OpenGraph date property
- setOpenGraphInteger() : mixed
- Set a custom OpenGraph integer property
- setOpenGraphString() : mixed
- Set a custom OpenGraph string property
- setPageType() : mixed
- The page type, i.e. "og:type" property
- setTitle() : mixed
- Set a title for this page. Don't include the site name
- setTwitterCardType() : mixed
- The twitter card type, i.e. "twitter:card" property
- setUrl() : mixed
- Set the canonical url for this page
- autoGenerateMissing() : mixed
- Auto-generate missing OpenGraph and Twitter cards meta data.
- addMetaNeedName() : void
- Add a needs entry for a meta 'name' tag of the specified name and value
- addMetaNeedProperty() : void
- Add a needs entry for a meta 'property' tag of the specified property and value
Properties
$meta_name
Tags of the form <meta name=":key" content=":val">
private
static mixed
$meta_name
= []
$meta_property
Tags of the form <meta property=":key" content=":val">
private
static mixed
$meta_property
= []
Methods
get()
public
static get() : array<string|int, mixed>
Return values
array<string|int, mixed> —[ properties[], names[] ]
hasTitle()
Has a page title been set?
public
static hasTitle() : bool
Return values
bool —True if a title has been set
render()
Render the social metadata
public
static render() : mixed
Handled by Needs already
setDescription()
Set a short (up to two sentence) description for this page
public
static setDescription(string $val) : mixed
Parameters
- $val : string
setImage()
Set the image for this page - should be unique to this page; not shared across the site
public
static setImage(string|null $url) : mixed
Parameters
- $url : string|null
-
Relative or absolute url
setOpenGraphDate()
Set a custom OpenGraph date property
public
static setOpenGraphDate(string $property, DateTimeInterface|string $value) : mixed
Parameters
- $property : string
-
Property name, e.g. 'article:published_time'
- $value : DateTimeInterface|string
-
A DateTime or anything paresable by the DateTime constructor
setOpenGraphInteger()
Set a custom OpenGraph integer property
public
static setOpenGraphInteger(string $property, int $value) : mixed
Parameters
- $property : string
-
Property name, e.g. 'music:album:track'
- $value : int
-
Property value, e.g. 4
setOpenGraphString()
Set a custom OpenGraph string property
public
static setOpenGraphString(string $property, string $value) : mixed
Parameters
- $property : string
-
Property name, e.g. 'article:section'
- $value : string
-
Property value, e.g. 'Technology'
setPageType()
The page type, i.e. "og:type" property
public
static setPageType(string $val) : mixed
Current options are: article, book, profile, website, music.song, music.album, music.playlist, music.radio_station, video.movie, video.episode, video.tv_show, video.other
Parameters
- $val : string
setTitle()
Set a title for this page. Don't include the site name
public
static setTitle(string $val) : mixed
Parameters
- $val : string
setTwitterCardType()
The twitter card type, i.e. "twitter:card" property
public
static setTwitterCardType(string $val) : mixed
Current options are: summary, summary_large_image, app, player Note that the player card requires approval from Twitter prior to use
Parameters
- $val : string
setUrl()
Set the canonical url for this page
public
static setUrl(string $url) : mixed
Parameters
- $url : string
-
Relative or absolute url
autoGenerateMissing()
Auto-generate missing OpenGraph and Twitter cards meta data.
protected
static autoGenerateMissing() : mixed
addMetaNeedName()
Add a needs entry for a meta 'name' tag of the specified name and value
private
static addMetaNeedName(string $name, string $value) : void
Parameters
- $name : string
-
The name of the tag
- $value : string
-
The value of the tag
addMetaNeedProperty()
Add a needs entry for a meta 'property' tag of the specified property and value
private
static addMetaNeedProperty(string $property, string|int $value) : void
Parameters
- $property : string
-
The property name
- $value : string|int
-
The property value