PHP code example of lukaswhite / meta-tags
1. Go to this page and download the library: Download lukaswhite/meta-tags library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lukaswhite / meta-tags example snippets
$meta = new MetaTags( );
$meta
->charSet( 'utf-8' )
->title( $title )
->description( $description )
->keywords( $keywords )
->robotsShouldIndexButNotFollow( )
->canonical( $url );
<!DOCTYPE html>
<html lang="en">
<head>
{!! $meta !!}
</head>
{!! app( )->make( MetaTags::class )->render( ) !!}
use Lukaswhite\MetaTags\MetaTags;
$meta = new MetaTags( );
$this->app->singleton( MetaTags::class, function( $app ) {
return new MetaTags( );
} );
$meta = app( )->make( MetaTags::class );
$meta->title( 'My Website' );
$meta->le( 'My Website' );
$meta->description( 'A description of the website' );
$meta->cription( 'A description of the website' );
<meta name="description" content="A description of the website" />
$meta->keywords( 'PHP', 'meta tags', 'SEO' );
$meta->url( 'http://example.com' );
$meta->charSet( 'ISO-8859-1' );
<meta charset="ISO-8859-1" />
$meta->charSet( null );
$meta->canonical( 'http://example.com' );
<link rel="canonical" content="http://example.com" />
$meta->previousPage( 'http://example.com/articles/page/3' )
->nextPage( 'http://example.com/articles/page/5' );
$meta
->firstPage( 'http://example.com/articles/page/1' )
->lastPage( 'http://example.com/articles/page/10' );
$meta->addRssFeed( 'http://example.com/feed.rss' );
$meta->addRssFeed( 'http://example.com/feed.rss', 'My Website RSS Feed' );
$meta->addAtomFeed( 'http://example.com/feed.xml' );
$meta->addAtomFeed( 'http://example.com/feed.xml', 'My Website Atom Feed' );
$meta->robotsShouldIndexButNotFollow( );
// or
$meta->robotsShouldFollowButNotIndex( );
// or
$meta->robotsShouldNotIndexNorFollow( );
$meta->googleShouldNotIncludeSnippets( );
$meta->googleShouldNotIncludeSnippets( );
$meta->googleShouldNotShowPageAsReferringPageForImageSearchResults( );
$meta->googleShouldStopCrawlingAfter( new \DateTime( '2019-10-23' ) );
$meta->addPrefetchLink( '/scripts.js' );
$meta->addPrefetchLink( '/scripts.js', 'script' );
$meta->addPreloadLink( '/scripts.js' );
$meta->addPreloadLink( '/scripts.js', 'script' );
$meta->addPreconnect( '//cdn.example.com' );
$meta->addPrerender( '//example.com/landing-page.html' );
$meta->httpEquiv( 'Pragma', 'no-cache' );
$meta->tellBrowsersNotToCache( );
$meta->custom( 'google-maps', 'your-google-maps-key' );
$meta->custom( 'mixpanel', getenv( 'MIXPANEL_APP_ID' ) );
$meta->custom( 'csrf-token', csrf_token( ), 'name' );
$meta->
$meta
->title( 'My Website' )
->description( 'A description of the website' )
->url( 'http://example.com' );
$meta->type( 'article' );
$meta->type( MetaTags::OG_TYPE_ARTICLE );
$meta->type(
MetaTags::OG_TYPE_BOOK,
[
'isbn' => 'ISBN-123-1234',
]
);
// or
$meta->type(
MetaTags::OG_TYPE_PROFILE,
[
'first_name' => 'Joe',
'last_name' => 'Bloggs',
'username' => 'joebloggs',
]
);
$meta->isArticle( );
$meta->isBook( );
$meta->isProfile( );
$meta->isBusiness( );
$meta->locale( 'en_GB' );
$meta->ogUrl( 'https://example.com' );
$meta->openGraph( 'determiner', 'an' );
$meta->openGraph( 'updated_time', new \DateTime( '2018-10-12' ) );
$meta->openGraph( 'restrictions:age', 18 );
$meta->addImage(
( new \Lukaswhite\MetaTags\Entities\Image( ) )
->setUrl( 'http://example.com/image.jpeg' )
->setSecureUrl( 'https://example.com/image.jpeg' )
->setType( 'image/jpeg' )
->setWidth( 500 )
->setHeight( 300 )
->setAlt( 'Example image' )
);
$meta->addVideo(
( new \Lukaswhite\MetaTags\Entities\Video( ) )
->setUrl( 'http://example.com/movie.swf' )
->setSecureUrl( 'https://example.com/movie.swf' )
->setType( 'application/x-shockwave-flash' )
->setWidth( 500 )
->setHeight( 300 )
->setImage( 'http://example.com/movie-image.jpg' )
);
$meta->addAudio(
( new \Lukaswhite\MetaTags\Entities\Audio( ) )
->setUrl( 'http://example.com/audio.mp3' )
->setSecureUrl( 'https://example.com/audio.mp3' )
->setType( 'audio/mp3' )
);
$meta->profile(
( new \Lukaswhite\MetaTags\Entities\Profile( ) )
->setFirstName( 'Joe' )
->setLastName( 'Bloggs' )
->setUsername( 'joebloggs' )
->setGender( \Lukaswhite\MetaTags\Contracts\Profile::MALE ) );
$meta->book(
( new \Lukaswhite\MetaTags\Entities\Book( ) )
->setReleaseDate( new \DateTime( '2018-04-03 15:20' ) )
->setAuthor( 'Joe Bloggs' )
->setIsbn( 'ISBN-123-1234' )
->setTag( [ 'PHP' ] )
);
$book->setAuthor( [ 'Joe Bloggs', 'Harry Black' ] );
$meta->contactData(
( new \Lukaswhite\MetaTags\Entities\ContactData( ) )
->setStreetAddress( '1601 S California Ave' )
->setLocality( 'Palo Alto' )
->setRegion( 'CA' )
->setPostalCode( '94304' )
->setCountryName( 'USA' )
->setEmail( '[email protected] ' )
->setPhone('650-123-4567')
->setFaxNumber('+1-415-123-4567')
->setWebsite( 'http://example.com' )
);
class Business implements ContactData {
// getStreetAddress( ), getPostalCode( ) etc
}
$meta->contactData( $business );
$meta->streetAddress( '1601 S California Ave' )
->locality( 'Palo Alto' )
->region( 'CA' )
->postalCode( '94304' )
->countryName( 'USA' )
->email( '[email protected] ' )
->phone('650-123-4567')
->faxNumber('+1-415-123-4567')
->website( 'http://example.com' )
);
$meta->addGeopoint(
new Geopoint( 37.416343, -122.153013 )
);
$meta->businessHours(
new BusinessDay( 'Monday', '09:00', '17:00' ),
new BusinessDay( 'Tuesday', '09:00', '17:00' ),
new BusinessDay( 'Wednesday', '09:00', '17:00' ),
new BusinessDay( 'Thursday', '09:00', '17:00' ),
new BusinessDay( 'Friday', '09:00', '17:00' ),
new BusinessDay( 'Saturday', '08:00', '18:00' )
);
$meta->facebookAppId( '12345678910' );
$meta->facebookProfileId( '78676576576' );
$meta->facebookAdmins(
'12345',
'678910'
);
// or
$meta->facebookAdmins(
'12345'
);
$meta->facebookPages(
'76236783',
'67873687'
);
// or
$meta->facebookPages(
'76236783'
);
$meta->twitterCard( );
<meta name="twitter:card" content="summary" />
$meta->twitterCard( MetaTags::TWITTER_CARD_SUMMARY_LARGE_IMAGE );
$meta->twitterCard( MetaTags::TWITTER_CARD_APP );
$meta->twitterCard( MetaTags::TWITTER_CARD_PLAYER );
$meta
->twitterSite( '@lukaswhite' )
->twitterCreator( '@lukaswhite' );
$meta
->twitterTitle( 'My Twitter' )
->twitterDescription( 'A Twitter description' );
$meta
->title( 'My Website' )
->description( 'A website' )
->twitterCard( )
->twitterSite( '@lukaswhite' )
->twitterCreator( '@lukaswhite' );
->addImage(
( new \Lukaswhite\MetaTags\Entities\Image( ) )
->setUrl( 'http://example.com/image.jpeg' )
->setSecureUrl( 'https://example.com/image.jpeg' )
->setType( 'image/jpeg' )
->setWidth( 500 )
->setHeight( 300 )
->setAlt( 'Example image' )
);
$this->app->singleton( MetaTags::class, function( $app ) {
$meta = new MetaTags( );
$meta->siteName( array_get( $app[ 'config' ], 'app.name' ) );
return $meta;
} );
$meta = app( )->make( MetaTags::class );
class PagesController {
public function show( Page $page )
{
app( )->make( MetaTags::class )
->title( $page->title )
->description( $page->description );
// The rest of the method
}
}
class RestaurantController {
public function show( Restaurant $restaurant )
{
app( )->make( MetaTags::class )
->isBusiness( )
->title( $restaurant->name )
->description( $restaurant->description )
->addGeopoint(
new Geopoint(
$restaurant->lat, $restaurant->lng
)
)
->streetAddress( $restaurant->street_address )
->locality( $restaurant->locality )
->region( $restaurant->locality )
->postalCode( $restaurant->postal_code )
->country( $restaurant->country )
->phone( $restaurant->phone );
// The rest of the method
}
}
class RestaurantController {
public function show( Restaurant $restaurant )
{
app( )->make( MetaTags::class )
->isBusiness( )
->title( $restaurant->name )
->description( $restaurant->description )
->addGeopoint( $restaurant )
->contactData( $restaurant );
// The rest of the method
}
}
class User extends Model implements Profile {
public class getFirstName( )
{
return $this->attributes[ 'first_name' ];
}
public class getLastName( )
{
return $this->attributes[ 'last_name' ];
}
public class getUsername( )
{
return $this->attributes[ 'username' ];
}
public class getGender( )
{
return $this->attributes[ 'gender' ];
}
}
class ProfileController {
public function show( User $user )
{
app( )->make( MetaTags::class )
->profile( $user );
// The rest of the method
}
}
<html>
<head>
print $meta->render( );
<html>
<head>
{!! $meta->render( ) !!}
</head>
$meta->geoPosition( new Geopoint( 37.416343, -122.153013 ) )
->geoPlaceName( 'London' )
->geoRegion( 'GB' );
<!DOCTYPE html>
<html lang="en">
<head>
{!! $meta !!}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/assets/styles.min.css">
</head>
$meta->viewport( 'width=device-width, initial-scale=1' )
->addLink( '/assets/styles.min.css', 'stylesheet' );
html
<meta name="keywords" content="PHP, meta tags, SEO" />