Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add or replace canonical URL to refere to another domain? #209

Closed
8parth opened this issue May 13, 2017 · 7 comments
Closed

How to add or replace canonical URL to refere to another domain? #209

8parth opened this issue May 13, 2017 · 7 comments

Comments

@8parth
Copy link
Contributor

8parth commented May 13, 2017

The plugin adds canonical-url by default. I want to replace that default url on some specific pages if another canonical-url exists.

So I added following in head section of my blog,

{% if page.canonical_url != nil %}
  <link rel="canonical" href="{{ page.canonical_url }}"/>
{% endif %}

So whenever a post has canonical_url specified in it's front-matter above snippet adds that canonical url. But, there is also one default generated canonical url tag added by {% seo %} field.

Is this expected behavior, or do I need to get rid of default generated canonical url tag? And, if that's the case how can I replace default canonical url with custom one for specific pages?

@pathawks
Copy link
Member

It is not currently possible to disable the plugin’s outputting of the canonical tag.

Can you explain your use case a bit more? Why do you want the canonical URL to point to a different domain?

@8parth
Copy link
Contributor Author

8parth commented May 13, 2017

I run my blog with Jekyll, and regularly post articles on different tech blogs. So, I want to republish content to my own blog with original article's url as canonical tag.

Is having two canonical links pointing to different domains(one at my website, one at original article link) okay? (I don't have much knowledge on SEO so if you can suggest me something or point me to right direction that'd be great)

@8parth
Copy link
Contributor Author

8parth commented May 14, 2017

Update: Currently jekyll-seo-tag merges site url with page url and generates final canonical url. If for a specific page canonical_url is explicitly defined by user, we can assign the url to canonical url otherwise use default generated url.

Here is my implementation:

# drop.rb
def canonical_url
  @canonical_url ||= begin
    if page["canonical_url"].present?
      page["canonical_url"].to_s.gsub(%r!/index\.html$!, "/")
    else
      filters.absolute_url(page["url"]).to_s.gsub(%r!/index\.html$!, "/")
    end
  end
end

@pathawks if this works fine I can submit PR or you can integrate these changes?

@jekyllbot
Copy link
Contributor

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

@benbalter
Copy link
Collaborator

if this works fine I can submit PR or you can integrate these changes?

@8parth Please do!

@jekyllbot jekyllbot removed the stale label Jul 17, 2017
@8parth
Copy link
Contributor Author

8parth commented Jul 18, 2017

@benbalter this issue is solved with PR #211 and merged, so I am closing this issue. Thanks for providing opportunity to contribute!

@8parth 8parth closed this as completed Jul 18, 2017
@ylogx
Copy link

ylogx commented Jan 28, 2019

Following worked for me:

    {% if page.canonical_url != nil %}
    <link rel="canonical" href="{{ page.canonical_url }}"/>
    {% else %}
    <link rel="canonical" href="{{ page.url | replace:'index.html','' | prepend: site.baseurl | prepend: site.url }}">
    {% endif %}

@jekyll jekyll locked and limited conversation to collaborators Jan 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants