artesaos/seotools

Default title doesn't append in og tags

lotarbo opened this issue · 3 comments

What steps will reproduce the problem?

use default title in config with titleBefore = true

set title in controller like
SEOTools::setTitle($page->title);

in blade file
{!! SEO::generate() !!}

What is the expected result?

<title>Site name - Home</title>
<meta property="og:title" content="Site name - Home" />
<meta name="twitter:title" content="Site name - Home" />

What do you get instead?

<title>Site name - Home</title>
<meta property="og:title" content="Home" />
<meta name="twitter:title" content="Home" />

Additional info

<?php
/**
 * @see https://github.com/artesaos/seotools
 */

return [
    'meta' => [
        /*
         * The default configurations to be used by the meta generator.
         */
        'defaults'       => [
            'title'        => "Site name", // set false to total remove
            'titleBefore'  => true, // Put defaults.title before page title, like 'It's Over 9000! - Dashboard'
            'description'  => 'For those who helped create the Genki Dama', // set false to total remove
            'separator'    => ' - ',
            'keywords'     => [],
            'canonical'    => false, // Set null for using Url::current(), set false to total remove
            'robots'       => false, // Set to 'all', 'none' or any combination of index/noindex and follow/nofollow
        ],
        /*
         * Webmaster tags are always added.
         */
        'webmaster_tags' => [
            'google'    => null,
            'bing'      => null,
            'alexa'     => null,
            'pinterest' => null,
            'yandex'    => null,
            'norton'    => null,
        ],

        'add_notranslate_class' => false,
    ],
    'opengraph' => [
        /*
         * The default configurations to be used by the opengraph generator.
         */
        'defaults' => [
            'title'       => false, // set false to total remove
            'description' => 'For those who helped create the Genki Dama', // set false to total remove
            'url'         => null, // Set null for using Url::current(), set false to total remove
            'type'        => false,
            'site_name'   => false,
            'images'      => [],
        ],
    ],
    'twitter' => [
        /*
         * The default values to be used by the twitter cards generator.
         */
        'defaults' => [
            //'card'        => 'summary',
            //'site'        => '@LuizVinicius73',
        ],
    ],
    'json-ld' => [
        /*
         * The default configurations to be used by the json-ld generator.
         */
        'defaults' => [
            'title'       => false, // set false to total remove
            'description' => 'For those who helped create the Genki Dama', // set false to total remove
            'url'         => false, // Set null for using Url::current(), set false to total remove
            'type'        => 'WebPage',
            'images'      => [],
        ],
    ],
];

Q A
This Package Version 0.20.0
Laravel Framework Version 8.29.0
PHP version 7.4.15
Operating system macos
J-Brk commented

I would expect the same result as you mention in this ticket, however based on the unit test it seems to be the expected result. The configuration file also seems to suggest that "titleBefore" only applies to the title and not to other segments.

So it seems like a design choice, @vinicius73 can you share your thoughts on this?

public function test_set_title()
{
$this->seoTools->setTitle('Kamehamehaaaaaaa');
$expected = "<title>Kamehamehaaaaaaa - It's Over 9000!</title>";
$expected .= '<meta name="description" content="For those who helped create the Genki Dama">';
$expected .= '<meta property="og:title" content="Kamehamehaaaaaaa" />';
$expected .= '<meta property="og:description" content="For those who helped create the Genki Dama" />';
$expected .= '<meta name="twitter:title" content="Kamehamehaaaaaaa" />';
$expected .= '<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Kamehamehaaaaaaa","description":"For those who helped create the Genki Dama"}</script>';
$this->assertEquals('Kamehamehaaaaaaa - It\'s Over 9000!', $this->seoTools->getTitle());
$this->setRightAssertion($expected);
}

@J-Brk u right, but different title in tag and og tag looks strange for me)

That was intentional, but we are able to receive a change for that.