Git Product home page Git Product logo

Comments (5)

ArondeParon avatar ArondeParon commented on August 22, 2024 1

@jasonvarga thanks for getting back to me.

We have two collections on our website. The main difference between the two is the URL. We are using separate URLs for different targeting campaigns (short urls for print campaigns, longer urls for Adwords, for example).

The canonical tag is essential to make sure the two pages are not treated as duplicate content.

Adding a canonical tag to a singular page (which is how it works now) does not really add value. The exact reason for the canonical tag is to refer to other pages so that the page which is being referred to can be treated as the original source.

This is a pretty common SEO case, so I believe it would probably be best to expose the controls for this property in the SEO tab in the CP.

For now, we have created our own hotfix by creating our own Seo tag that extends SeoProTags as follows:

class SeoTags extends SeoProTags
{
    public function meta()
    {
        if (array_get($this->context, 'seo') === false) {
            return;
        }

        $data = (new TagData)
            ->with(Settings::load()->get('defaults'))
            ->with(array_get($this->context, 'seo', []))
            ->withCurrent(array_get($this->context, 'page_object'))
            ->get();

        // If this variable is set to true, the template will know that we're dealing with an override.
        $data['canonical'] = false;

        $canonical = $this->getParam('canonical');

        if ($canonical !== null) {
            $data['canonical'] = true;
            $canonicalEntry = Entry::find($canonical);
            if ($canonicalEntry) {
                $data['canonical_url'] = $canonicalEntry->absoluteUrl();
            }
        }

        return $this->render('meta', $data);
    }
}

Our non-canonical pages have a collection field in which the UUID of the canonical page is stored, so we call it like this: {{ seo:meta canonical=parent }}.

In our own meta.html we have made adjustments so that the canonical tag is only added when it is actually set and different from the current page URL as follows:

{{ if canonical_url && canonical }}
<link href="{{ canonical_url }}" rel="canonical" />
{{ /if }}

from seo-pro.

fitzage avatar fitzage commented on August 22, 2024 1

Can I at least disable the canonical URL feature in SEO Pro so I can build my own?

Here's our issue: we have some blog articles that have been turned into documentation pages. If people google the content, we want Google to know that the documentation page is the correct page, but redirecting the blog article would be a jarring user experience.

There's also the occasional cross-posted blog article where a partner may author an article that we also want to include on our site, but we want google to know the original copy is the canonical version.

So really, in some cases just redirecting the page makes the most sense, but sometimes setting the canonical URL is the best experience for the user.

from seo-pro.

jackmcdade avatar jackmcdade commented on August 22, 2024

They're already set automatically based on your Permalink.

from seo-pro.

ArondeParon avatar ArondeParon commented on August 22, 2024

@jackmcdade we're experiencing issues with this as well. Isn't the idea of canonical urls to be able to set them to something different than the current permalink?

We have tried overriding the values, but there currently does not seem to be a way to do this because TagData.php will simply set it to the absolute URL again.

Possible solutions would be:

  • allow the tag to accept context, that is automatically merged in TagData.php
    Example:
{{ seo_pro:meta canonical_url='/foo' }}
  • allow the canonical URL to be set through the CP, just like the title and description can be set. This seems to be the best solution.

Would love to hear your thoughts on this, because as it is now, the canonical URL functionality is not really usable. If I am overlooking something, I'd very much like to hear it too.

Thanks.

from seo-pro.

jasonvarga avatar jasonvarga commented on August 22, 2024

Can you explain in more detail why you are trying to set the canonical URL to something else? Do you mean you want to do it on a couple of pages or for the entire site?

from seo-pro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.