# age-gate/3.7.3/src/Presentation/Title.php

Age Gate, version 3.7.3. 85 lines.

- Page: https://pluginprobe.com/plugins/age-gate/3.7.3/code/src/Presentation/Title.php
- Raw: https://pluginprobe.com/plugins/age-gate/3.7.3/raw/src/Presentation/Title.php
- Modified: 2025-01-17T22:02:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/age-gate/3.7.3/code/src/Presentation/Title.php#L10-L20`.

```php
<?php

namespace AgeGate\Presentation;

use AgeGate\Common\Content;
use AgeGate\Common\Settings;

class Title
{
    private $settings;

    private $content;

    public function __construct(Content $content, Settings $settings)
    {
        $this->settings = $settings;
        $this->content = $content;

        if ($settings->method !== 'js' && $settings->switchTitle) {
            add_filter('wpseo_title', [$this, 'returnPageTitle'], 1000, 1);
            add_filter('rank_math/frontend/title', [$this, 'returnPageTitle'], 1000, 1);
            add_filter('document_title_parts', [$this, 'changePageTitle'], 1000, 1);
            add_filter('wp_title', [$this, 'changeDefaultTitle'], 10, 3);
        }

    }

    public function getTitle()
    {
        return $this->settings->customTitle . ' - ' . get_bloginfo('name');
    }

    /**
     * Change the page title for themes with theme_support
     * for title-tag
     *
     * @return array
     */
    public function changePageTitle($title = [])
    {
        if ($this->content->isRestricted()) {
            return [
                'title' => $this->settings->customTitle,
                'site' => get_bloginfo('name'),
            ];
        }

        return $title;
    }

    /**
     * Change the title for themes that
     * do not support title tag
     *
     * @param string $title
     * @param string $sep
     * @param string $location
     * @return string
     */
    public function changeDefaultTitle($title, $sep, $location)
    {

        if ($this->content->isRestricted()) {
            return $this->getTitle();
        }

        return $title;
    }

    /**
     * Change the parts sent to Yoast or Think Math
     *
     * @return void
     */
    public function returnPageTitle($title)
    {
        if ($this->content->isRestricted()) {
            return $this->getTitle();
        }

        return $title;
    }

}

```
