admin管理员组

文章数量:1136619

I got some problems using rank math SEO plugin, when I add links on posts and after publish I see rank math added class="rank-math-link" on every link.

<a href="//" class="rank-math-link">link text</a>

how can I remove that...?

I got some problems using rank math SEO plugin, when I add links on posts and after publish I see rank math added class="rank-math-link" on every link.

<a href="//" class="rank-math-link">link text</a>

how can I remove that...?

Share Improve this question asked Apr 20, 2020 at 8:21 Jenny DearbornJenny Dearborn 1 3
  • I think you'd have to ask them. At first glance it looks like it's added by their Gutenberg code, and isn't used or styled elsewhere, so there ought not be any harm in removing it unless it breaks some block editor integration (e.g. if it adds some extra properties to a link if this is present?) But I don't know Gutenberg or this plugin well so I'm speculating. – Rup Commented Apr 20, 2020 at 8:41
  • At a pinch you could write a post-save or post-update hook to remove these classes as you save the post to the DB. But I think it's better to ask Rank Math directly what these classes are for. – Rup Commented Apr 20, 2020 at 8:42
  • I ask them but they didn't solve this. So I want to put some on theme functions for that. – Jenny Dearborn Commented Apr 20, 2020 at 23:25
Add a comment  | 

2 Answers 2

Reset to default 0

I found this very irritating. So, I came up with my own solution. This filters the content before it gets sent to the browser while leaving the stored version in the DB unchanged. I believe Rank Math needs the class for Gutenberg special link options. Win-win for both you and Rank Math.

if ( !function_exists('filter_the_content_remove_rank_math_link') ) {
    /**
     * Remove/filter `rank-math-link` class added by Rank Math
     *
     * @param $content
     * @return string|string[]
     */
    function filter_the_content_remove_rank_math_link( $content )
    {
        // Check if we're inside the single Post.
        if ( is_singular() ) {
            $content = str_replace(['rank-math-link', 'class=""'], '', $content);
        }

        return $content;
    }

    add_filter('the_content', 'filter_the_content_remove_rank_math_link', 1);
}

Yes, you can also change the str_replace or used a regex

Rank math has function that will disable this.

https://rankmath.com/kb/filters-hooks-api-developer/#remove-rank-math-link-class

本文标签: themesi want remove class from post links