Jump to content

Recommended Posts

Posted

Further to above, there was an issue with the sitemap handling urlsegments with the canonical link. Another hook solved it for me:
 

Spoiler
// update canonical, twitter and OG urls with urlSegments
$wire->addHookAfter('SeoMaestro::renderMetatags', function($event) {
    $name = $event->arguments(0);
    $group = $event->arguments(1);
    if(!is_array($name) || !count($name)) return;
    if(is_null($group)) return;

    $input = $this->wire('input');
    $segments = $input->urlSegments();
    if(count($segments) < 1) return;

   $pageUrl = $this->wire('page')->httpUrl;
   $urlWithSegs = rtrim($pageUrl, '/') . '/' . $input->urlSegmentStr();

    switch($group) {
        case 'twitter':
        case 'opengraph':
            if(!isset($name['url'])) return;
            $name['url'] = str_ireplace($pageUrl, $urlWithSegs, $name['url']);
            break;

        case 'meta':
            if(!isset($name['canonicalUrl'])) return;
            $name['canonicalUrl'] = str_ireplace($pageUrl, $urlWithSegs, $name['canonicalUrl']);
            break;

        default:
            break;
    }
    $event->return = $name;
});

 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...