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

Ability to customize the [#item_url] tag #813

Closed
4 tasks
AndreeaCristinaRadacina opened this issue Oct 21, 2023 · 18 comments · Fixed by #963 or #966
Closed
4 tasks

Ability to customize the [#item_url] tag #813

AndreeaCristinaRadacina opened this issue Oct 21, 2023 · 18 comments · Fixed by #963 or #966
Assignees
Labels
doc-needed This issue requires documentation updates or additions once it has been completed. enhancement Request to improve or optimize an existing feature or functionality in the project Priority-Medium Expected resolution time - up to 1 month. released Indicate that an issue has been resolved and released in a particular version of the product.

Comments

@AndreeaCristinaRadacina

What problem does this address?

Right now, we have the [#item_url] tag that adds a personalized "Read More" link. However, the site admin has no control over the link.

What is your proposed solution?

Implement actions modal with some basic actions:

  • link text - write something else instead of Read More
  • opening behavior - in a new tab/same tab
  • link type - follow/nofollow link
  • tracking parameters/UTMs

Will this feature require documentation? (Optional)

Yes, it requires documentation.

@AndreeaCristinaRadacina AndreeaCristinaRadacina added the new feature Request for a new feature or functionality to be added to the project. label Oct 21, 2023
@pirate-bot pirate-bot added the doc-needed This issue requires documentation updates or additions once it has been completed. label Oct 21, 2023
@AndreeaCristinaRadacina
Copy link
Author

@AndreeaCristinaRadacina
Copy link
Author

@AndreeaCristinaRadacina
Copy link
Author

@AndreeaCristinaRadacina
Copy link
Author

@vytisbulkevicius
Copy link
Contributor

I think having an action for this is too complicated because we have same actions for all tags and creating new actions just for [#item_url] is too much but I would like to have a filter for this that would allow manipulating data.

@girishpanchal30, do you think we can create such a filter? Something like you suggested for custom tags in the past:
https://github.com/Codeinwp/feedzy-rss-feeds-pro/issues/447#issuecomment-1014334516

@vytisbulkevicius vytisbulkevicius added Priority-Medium Expected resolution time - up to 1 month. enhancement Request to improve or optimize an existing feature or functionality in the project and removed new feature Request for a new feature or functionality to be added to the project. labels Jul 31, 2024
@girishpanchal30
Copy link
Contributor

@girishpanchal30, do you think we can create such a filter? Something like you suggested for custom tags in the past:

@vytisbulkevicius Yes, It's better to create a new filter rather than a new action for item_url.

@girishpanchal30 girishpanchal30 linked a pull request Aug 1, 2024 that will close this issue
6 tasks
@girishpanchal30
Copy link
Contributor

@AndreeaCristinaRadacina @vytisbulkevicius I've added the new filter and I mentioned the example code in PR #963

@AndreeaCristinaRadacina
Copy link
Author

AndreeaCristinaRadacina commented Aug 1, 2024

@girishpanchal30 amazing!

Everything works well, apart from the link type (rel). I set it to nofollow, but it appears as noopener:

image image

Should I apply other settings for this to work?

Same results if I use: $item_link_data['attr']['rel'] = 'noopener noreferrer nofollow'; // noopener, nofollow.

@AndreeaCristinaRadacina
Copy link
Author

AndreeaCristinaRadacina commented Aug 1, 2024

@girishpanchal30 I also checked a similar guide before, but it's the same when I use _self/_parent and 'nofollow'.

Is it something we can control?

@AndreeaCristinaRadacina
Copy link
Author

I also removed this line: $item_link_data['attr']['rel'] = 'nofollow'; // noopener, nofollow.
And the rel attribute remains there, so it's like the above line is not considered at all

@vytisbulkevicius
Copy link
Contributor

@AndreeaCristinaRadacina,

I tried to play around and I also can't change it with the filter, its something WordPress doesn't want to allow manipulating for security reasons, another thread about it: https://wordpress.com/forums/topic/remove-relnoopener-wtf/

What worked for me and maybe we can recommend those clients who ask for it is using this one and manipulating DOM (it works without re-doing the import):

add_filter('the_content', 'ensure_rel_attribute', 20);

function ensure_rel_attribute($content) {
    // Use DOMDocument to ensure 'rel' attribute is set correctly
    $dom = new DOMDocument();
    libxml_use_internal_errors(true);
    $dom->loadHTML('<?xml encoding="utf-8" ?>' . $content);
    libxml_clear_errors();

    $links = $dom->getElementsByTagName('a');

    foreach ($links as $link) {
        if ($link->getAttribute('class') === 'feedzy-rss-link-icon') {
            $rel = $link->getAttribute('rel');
                $link->setAttribute('rel', 'nofollow');
        }
    }

    return $dom->saveHTML();
}

I look with it for feedzy-rss-link-icon class which that Read More button has and then change the rel attributes value to nofollow in this case.

@girishpanchal30 what do you think about this approach, any big cons recommending it if someone needs?

@girishpanchal30
Copy link
Contributor

@vytisbulkevicius @AndreeaCristinaRadacina I've removed the default WP link rel if found in our filter.

Here: 37e3e0d

Please check with the latest build zip.

@AndreeaCristinaRadacina
Copy link
Author

@girishpanchal30 Thank you!

Now, when I use the filter and declare a rel type, nothing is displayed:
image

If I comment that line, the default noopener is displayed:
image
image

Do you have any suggestions? Should I use this in combination with Vytis' code, or should it have worked as a standalone solution?

@girishpanchal30
Copy link
Contributor

@AndreeaCristinaRadacina

Do you have any suggestions? Should I use this in combination with Vytis' code, or should it have worked as a standalone solution?

It should work standalone

I've pushed new changes in PR, Can you please recheck with the latest build zip?

Thanks

@AndreeaCristinaRadacina
Copy link
Author

@girishpanchal30 Great, it works now!

@AndreeaCristinaRadacina
Copy link
Author

@vytisbulkevicius vytisbulkevicius linked a pull request Aug 9, 2024 that will close this issue
vytisbulkevicius added a commit that referenced this issue Aug 9, 2024
- Added support for a custom filter that allows modifications of the item_url tag for imported posts #813
pirate-bot added a commit that referenced this issue Aug 9, 2024
##### [Version 4.4.13](v4.4.12...v4.4.13) (2024-08-09)

- Added support for a custom filter that allows modifications of the item_url tag for imported posts [#813](#813)
@pirate-bot
Copy link
Contributor

🎉 This issue has been resolved in version 4.4.13 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-needed This issue requires documentation updates or additions once it has been completed. enhancement Request to improve or optimize an existing feature or functionality in the project Priority-Medium Expected resolution time - up to 1 month. released Indicate that an issue has been resolved and released in a particular version of the product.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants