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

Anchors don't work properly when copying/pasting #21353

Open
5 of 11 tasks
Rvervuurt opened this issue Apr 30, 2024 · 6 comments
Open
5 of 11 tasks

Anchors don't work properly when copying/pasting #21353

Rvervuurt opened this issue Apr 30, 2024 · 6 comments

Comments

@Rvervuurt
Copy link

Rvervuurt commented Apr 30, 2024

  • I've read and understood the contribution guidelines.
  • I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened

Whenever my colleagues copy content into a page or custom post type from Google Docs, that includes a headline and some text, Yoast doesn't generate an anchor for the headline.

As soon as I add a letter to the headline, it generate an anchor tag, but we of course want that anchor tag to be generated when pasting the whole piece!

To Reproduce

Step-by-step reproduction instructions

  1. Copy the content of this document
  2. Create a new post or page in a Wordpress website
  3. Paste the content from step 1 in the page
  4. You'll notice the anchor input field is empty
image image
  1. When adding a random letter to the headline, the anchor tag is generated:
image

Note: as seen in the video below, the headline in the first paste actually generates an anchor tag, but every headline after that doesn't.

Expected results

  1. When pasting a headline and some rich text, I expect Yoast to generate an anchor tag for the headline in the copied content

Actual results

  1. There is no anchor tag on the headline

Screenshots, screen recording, code snippet

d585ab2c-8878-470b-9089-dc9c12f06f66.mp4

Technical info

  • If relevant, which editor is affected (or editors):
  • Block Editor
  • Gutenberg Editor
  • Elementor Editor
  • Classic Editor
  • Other:
  • Which browser is affected (or browsers):
  • Chrome
  • Firefox
  • Safari
  • Other:

Used versions

  • Device you are using: Macbook Pro
  • Operating system: Mac OS Sonoma 14.4.1
  • PHP version: 8.2
  • WordPress version: 6.5.2
  • WordPress Theme: Custom
  • Yoast SEO version: 22.6
@josevarghese
Copy link
Contributor

josevarghese commented May 6, 2024

Hi @Rvervuurt

Thanks for using the Yoast SEO plugin and also for creating the issue. Our Table of Contents block uses the HTML Anchor feature, which is available on the Yoast SEO Premium, to navigate to the heading from the ToC. So when I tried to copy-paste the document from Google Docs with headings, I noticed that the HTML Anchor get generated correctly on the block editor for all the headings automatically.

toc

If you are not using Yoast SEO Premium, we recommend you purchase one for your website. and you can test this on the demo site having Yoast SEO Premium at here

Closing this issue as we are providing this functionality on the Yoast SEO Premium plugin.

@Rvervuurt
Copy link
Author

Rvervuurt commented May 13, 2024

I am using Yoast SEO premium. :)

Based on your screenshot, you pasted the piece of text once. Can you try pasting it twice, and see if the 2nd one also gets an HTML anchor? I added a note, to clarify that the first paste gets the correct anchor, but the 2nd doesn't, but I guess it wasn't clear enough.

@josevarghese
Copy link
Contributor

Hi @Rvervuurt

Thanks for using Yoast SEO Premium on your website.

First, please note that most posts won't have the same heading mentioned twice, as this will confuse users, and it's a different use case if you are using the same heading for a post twice. So, making some changes to the second heading that you have copied again will help our plugin generate the HTML anchor automatically.

Also, instead of copying the same heading words and paragraph again from the Google Document, try to copy the same heading and paragraph that you have added to the block post before, it will help our plugin to increment the HTML anchor by adding -0 -1 -2 to the end of the HTML Anchor as our plugin can detect the previous HTML anchor for the same heading before. See the screencast for your reference: https://www.loom.com/share/05a292405d3b44a48efbe6ee09d8b7e5

Thanks

@Rvervuurt
Copy link
Author

Hi @josevarghese, thanks for the quick reply!

I see that I'm working on an edge case here :) Please see this recording, where I do the following:

  1. I copy the first title + text into my page -> This generates an anchor tag
  2. After that, I copy and paste the 2nd title + text -> This doesn't generate an anchor tag

I have updated the document, so you can copy/paste the exact same content as I do.

@josevarghese
Copy link
Contributor

Hi @Rvervuurt

Thanks for the reply. I forgot to update you after testing it. I can replicate the issue you have pointed out by copying and pasting the headings one by one. I also created an internal bug for the team to take a closer look.

As a workaround, I recommend copying and pasting the whole text from the Google doc in a single step instead of copying it seperately. This will help our plugin generate the anchor links without any issues.

@josevarghese josevarghese reopened this May 30, 2024
@Rvervuurt
Copy link
Author

Amazing, thanks for updating and reopening!

I also found out that adding a single character (and removing it immediately) to a title without anchor also generates it, so if we can't copy the whole text at once (there are situations where we can't, which is why we found this bug), we'll fall back to that.

Good luck with trying to fix this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants