Meta class can be initialized as shown below.
<?php
use \spoova\mi\core\classes\Meta;
$meta = new Meta;
<?php
use \spoova\mi\core\classes\Meta;
$meta = new Meta('UTF-8');
$meta = new Meta();
$meta->charset('UTF-8'); // set meta character type
add method is used to add attributes to meta tags.
Example is shown below:
$meta->add($name, $content, $type);
where:
$name : the name, property or http-equiv attribute value of meta a tag.
$content : the content attribute of meta tags
$type : the type of meta tag. Options - [name|property|http-equiv]
default type is name.
$meta->add('viewport', 'width=device-width, initial-scale=1.0');
$meta->add('robots', 'noindex, nofollow');
$meta->add('description','150 words');
$meta->add('og:type', 'game.achievement', 'property');
$meta->add('Pragma', 'no-cache', 'http-equiv');
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="robots" content="noindex, nofollow"/> <meta name="description" content="150 words"/> <meta property="og:type" content="game.achievement"/> <meta http-equiv="Pragma" content="no-cache"/>
name method is a shorthand for the meta tags with the attribute of property.
Example is shown below:
$meta->name(name, content);
where:
name : the name attribute value of meta tag
content : the content attribute value of meta tag
$meta->name('description', '150 words');
<meta name="description" content="150 words"/>
prop method is a shorthand for the meta tags with the attribute of property.
Example is shown below:
$meta->prop(property, content);
where:
property : the property attribute value of meta tag
content : the content attribute value of meta tag
$meta->prop('og:type', 'game.achievement');
<meta property="og:type" content="game.achievement"/>
equiv method is a shorthand for the meta tags with the attribute of http-equiv.
Example is shown below:
$meta->equiv(http-equiv, content);
where:
http-equiv : the http-equiv attribute value of meta tag
content : the content attribute value of meta tag
$meta->equiv('Pragma', 'no-cache',);
<meta http-equiv="Pragma" content="no-cache"/>
refresh method is a shorthand for the meta tags with the attribute of
http-equiv="refresh". Example is shown below:
$meta->refresh(time);
where:
time : time in seconds
$meta->refresh(30);
<meta http-equiv="refresh" content="30"/>
og method is a shorthand for the meta tags with the attribute of
property="og:".
Example is shown below:
$meta->og(type, content);
where:
type : og type.
content : content atttribute of og meta tags.
$meta->og('type', 'game.achievement');
<meta property="og:type" content="game.achievement"/>
link method is used to add properties link meta tags.
Examples are shown below:
$meta->link(rel, href, attrs);
where:
rel : relativity attribute of link tag.
href : href atttribute of link tags.
attrs: other attributes of link tag
$meta->link('icon', 'https://somesite.com/icon.png",['type' => 'image/png']);
<link rel="icon" href="https://somesite.com/icon.png" type="image/png" />
drop() method removes all stored meta definitions from storage list.
$meta->add('description', '150 words');
$meta->drop(); // clear previous descriptions
export() method displays all stored meta definitions from storage list on each line.
$meta->export(); // displays each predefined meta tags in a listed order
dump() method returns all stored meta tags. However, when a boolean argument of true
is supplied, it prints out all stored meta tags.
$meta->add('description', '150 words');
vdump($meta->dump()); // return predefined meta tags
$meta->dump(true); // prints predefined meta tags
sample() method returns an array of meta tag samples. This data
was compiled from across different source on the internet.
vdump( $meta->sample() ); // outputs array of meta tag sample attributes