WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Remove rel from next_post_link (3 posts)

  1. NIkesh Kr Yadav
    Member
    Posted 1 year ago #

    hi i am using
    <?php next_post_link( '%link class="prev" ', '<span></span> Previous Article', FALSE, '27 and 18 and 19 and 20 and 21 and 14' ); ?>
    and its output is <a href="http://example.com/adfasdfa-1/" rel="prev"><span></span> Next Article</a>

    in this i want to remove rel="prev" and wants to add class="prev"

  2. bcworkz
    Member
    Posted 1 year ago #

    You could hook the filter 'next_post_link'. Your hook function is passed the output string from your next_post_link() function call. You can use basic string operations to alter it as needed. Whatever you return is directly echoed out to the user's browser.

  3. NIkesh Kr Yadav
    Member
    Posted 1 year ago #

    Thanks for help i have solved it as

    function add_class_next_post_link($html){
        $html = str_replace('<a','<a class="prev"',$html);
        return $html;
    }
    add_filter('next_post_link','add_class_next_post_link',10,1);
    function add_class_previous_post_link($html){
        $html = str_replace('<a','<a class="next"',$html);
        return $html;
    }
    add_filter('previous_post_link','add_class_previous_post_link',10,1);

Topic Closed

This topic has been closed to new replies.

About this Topic