Snippets
Created by
DACHCOM
last modified
Comments (11)
You can clone a snippet to your computer for local editing. Learn more.
You can clone a snippet to your computer for local editing. Learn more.
I have tried your script in my website, which uses ACF PRO and Yoast SEO. In my console, I could see that the fields were picked up, but not all of them:
div[data-name]
(line 39) matches the parent repeater, and not the current element. I had to usediv[data-name],td[data-name]
instead. Alternatively, you could use[data-name]
to match any element with this property.data-key
-property which is already present at the matched element on line 39? I have changed line 42 to:$el.data('key'),
(note: this line ends with a comma, because more variables are defined on the next lines.) The only 'drawback' of this approach is that thedata-key
is slightly different from the id that the current code uses. Thedata-key
is of the formatfield_<code>
, while the id is of the formatacf-field_<code>
.removeContent()
is called and all of my custom field contents are removed from Yoast. I have not yet found a solution for this issue, but wonder why you are traversing the whole content array when an element is removed, instead of removing the current content provided in the$el
variable.value
(inserted at line 45):Note: this code only provides a way of adding repeater data, the removal of repeater elements is not yet provided.
I will continue to use your script, and will post a working example here when it is ready. Please contact me if you need more information or have answers to the questions raised above.
An update to my previous comment: I have created a working script. Additional features:
wrap-in-*
can be added, which renders the text contents as an HTML tag for Yoast. This is particularly useful for fields that will be formatted as a heading in your template. For example, when you usewrap-in-h2
for a text field with value "Heading", the output privided to Yoast will be<h2>Heading</h2>
. Caution: this is a very powerful feature, use it wisely. Alternatively, the regexp could be altered to/wrap-in-(h\d)/
.change
-event is fired on the repeater when a repeater element is added or removed, theremove
-event could be removed.textarea
-element, as suggested by pavelgro on the ACF forum.ToDo:
Edit: Work with Objects instead of arrays, because keys are not numeric for new repeater items.
Thanks for your work! I will test it tomorrow. Would you like to create a git repo for this? :) So I can easily update and support you will pull requests!
@TimVevida Thanks also from me for your work. I would also prefer if you could create a git repo. I will make tests tomorrow!
I will wait until Stefan Hagspiel responses.
As the script is originally created by @dachcom, I will wait for their response first. The script says 'all rights reserved', so I don't feel free creating a Git repository.
hey guys. thanks for your work! i'll pack this snippet into a small plugin and then move the whole pile over to github. stay tuned.
Nice!
@dachcom: I will. Thanks for the reply.
Repo is available: https://github.com/dachcom-digital/acf-yoast-seo-validation
@mjnet: I am interested in how you would test this code. See the corresponding issue on GitHub.