How to add rel="noopener follow" in all the links of a specific custom post type?

Discussion in 'WordPress' started by Divvy, Jan 22, 2023.

  1. #1
    Hello guys,

    Is it possible to change the rel tag of a specific custom post type? Is there any snippet that can do this?

    The code that is showing in my custom post type:
    <a href="https://" rel="noopener" target="_blank">title</a>
    PHP:
    I need to show like this:
    <a href="https://" rel="noopener follow" target="_blank">title</a>
    PHP:
    Than you in advance :)
     
    Divvy, Jan 22, 2023 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,373
    Likes Received:
    1,720
    Best Answers:
    31
    Trophy Points:
    475
    #2
    Not wordpress specific, but in php you can do something like this:

    <?php
    
    $str = '<a href="https://" rel="noopener" target="_blank">title</a>';
    $pattern = '/noopener/i';
    echo preg_replace($pattern, 'noopener follow', $str);
    
    ?>
    Code (markup):
     
    qwikad.com, Jan 22, 2023 IP
  3. Divvy

    Divvy Well-Known Member

    Messages:
    785
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #3
    Thank you mate, fixed! :)
     
    Divvy, Jan 27, 2023 IP