PHP code example of jacky525 / seo

1. Go to this page and download the library: Download jacky525/seo 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/ */

    

jacky525 / seo example snippets


use Melbahja\Seo\Factory;

$schema = Factory::schema('organization')
            ->url('https://example.com')
            ->logo('https://example.com/logo.png')
                ->contactPoint
                    ->telephone('+1-000-555-1212')
                    ->contactType('customer service');

echo $schema;

use Melbahja\Seo\Factory;

$schema = Factory::schema('book')
            ->name('The Book Name')
            ->url('https://example.com/books/the-book')
            ->author
                ->set('@type', 'Person')
                ->name('J.D. Jhon')
            ->getRoot();

echo json_encode($schema, JSON_PRETTY_PRINT);

use Melbahja\Seo\Factory;

$schema = Factory::schema('product')
            ->image(['https://example.com/image.jpeg', 'https://example.com/2.jpeg'])
            ->name('The Product Name')
            ->description('Product description...')
            ->sku('12828127112')
            ->brand->set('@type', 'Thing')->name('Brand Name')
            ->getParent()->aggregateRating->ratingValue("4.4")->ratingCount("89")
            ->getParent()->review(
            [
                'reviewRating' => 
                [
                    '@type' => 'Rating',
                    'ratingValue' => '4',
                    'bestRating' => '5'
                ],

                'author' =>
                [
                    '@type' => 'Person',
                    'name' => "Mohamed ELbahja"
                ]
            ])
            ->offers
                ->set('@type', 'AggregateOffer')
                ->lowPrice('119.99')
                ->highPrice('200.99')
                ->priceCurrency('USD')
                ->availability('https://schema.org/InStock')
                ->offerCount('100');

echo $schema;


use Melbahja\Seo\Factory;

$metatags = Factory::metaTags(
[
	'title' => 'My new article',
	'description' => 'My new article about how php is awesome',
	'keywords' => 'php, programming',
	'robots' => 'index, nofollow',
	'author' => 'Mohamed Elbahja'
]);

echo $metatags;


use Melbahja\Seo\Factory;

$metatags = Factory::metaTags();

$metatags->meta('author', 'Mohamed Elabhja')
		->meta('title', 'PHP SEO')
		->meta('description', 'This is my description')
		->image('https://avatars3.githubusercontent.com/u/8259014')
		->mobile('https://m.example.com')
		->url('https://example.com')
		->shortlink('https://git.io/phpseo')
		->amp('https://amp.example.com')
		->facebook('prop', 'propValue example og')
		->twitter('prop', 'propValue example twitter');

echo $metatags;

$yourmap = Factory::sitemap(string $url, array $options = []): SitemapIndexInterface

use Melbahja\Seo\Factory;

$sitemap = Factory::sitemap('https://example.com', ['save_path' => '/path/to_save/files']);

$sitemap->links('blog.xml', function($map) 
{
    $map->loc('/blog')->freq('daily')->priority('0.8')
        ->loc('/blog/my-new-article')->freq('weekly')->lastMode('2019-03-01')
        ->loc('/اهلا-بالعالم')->freq('weekly');
    $map->loc('/blog/hello')->freq('monthly');
});

// return bool
// throws SitemapException if save_path options not exists
$sitemap->save();

use Melbahja\Seo\Factory;

$sitemap = Factory::sitemap('https://example.com');

// Instead of passing save_path to the factory you can set it later via setSavePath
// also $sitemap->getSavePath() method to get the current save_path
$sitemap->setSavePath('your_save/path');

// changing sitemap index name
$sitemap->setIndexName('index.xml');

// For images you need to pass a option images => true
$sitemap->links(['name' => 'blog.xml', 'images' => true], function($map) 
{
    $map->loc('/blog')->freq('daily')->priority('0.8')
        ->loc('/blog/my-new-article')
            ->freq('weekly')
            ->lastMode('2019-03-01')
            ->image('/uploads/image.jpeg', ['caption' => 'My caption'])
        ->loc('/اهلا-بالعالم')->freq('weekly');

    // image(string $url, array $options = []), image options: caption, geo_location, title, license
    // see References -> images   
    $map->loc('/blog/hello')->freq('monthly')->image('https://cdn.example.com/image.jpeg');
});

// another file
$sitemap->links('blog_2.xml', function($map) 
{
	// Mabye you need to loop through posts form your database ?
	foreach (range(0, 4) as $i)
	{
		$map->loc("/posts/{$i}")->freq('weekly')->priority('0.7');
	}
});

$sitemap->save();


$sitemap = Factory::sitemap('https://example.com')
                ->setSavePath('./storage/sitemaps')
                ->setSitemapsUrl('https://example.com/sitemaps')
                ->setIndexName('index.xml');

$sitemap->links(['name' => 'posts.xml', 'videos' => true], function($map) 
{
	$map->loc('/posts/clickbait-video')->video('My Clickbait Video title', 
	[
		// or thumbnail_loc 
		'thumbnail' => 'https://example.com/thumbnail.jpeg',
		'description' => 'My description',
		// player_loc or content_loc one of them is 

use Melbahja\Seo\Factory;

$sitemap = Factory::sitemap('https://example.com',
[
	// You can also customize your options by passing array to the factory like this
	'save_path' => './path',
	'sitemaps_url' => 'https://example.com/maps',
	'index_name' => 'news_index.xml'
]);

$sitemap->news('my_news.xml', function($map) 
{
    // publication: name, language
    // Google quote about the name: "It must exactly match the name as 
    // it appears on your articles on news.google.com"
    $map->setPublication('PHP NEWS', 'en');

    $map->loc('/news/12')->news(
    [
       'title' => 'PHP 8 Released',
       'publication_date' => '2019-03-01T15:30:02+01:00',
    ]);

    $map->loc('/news/13')->news(
    [
        'title' => 'PHP 8 And High Performance',
        'publication_date' => '2019-04-01T15:30:02+01:00'
    ]);
});

$sitemap->save();

use Melbahja\Seo\Factory;

// the void method send() will inform via CURL: google, bing and yandex about your new file
Factory::ping()->send('https://example.com/sitemap_file.xml');