0

I am really frustrated, I have tried working on this code but I am not getting it right, Though I am a novice in WP function coding. I want to skip specific html tag from my auto replace keyword with link function, Example I want to disable auto link on text that already have

Here is my below function, I don't know where I am getting it wrong

function wp_affiliate_links($text){
     if( is_single() && in_category( 'coco' ) ){

         $from = '!<h5>[^<>]*<\/h5>(*SKIP)(*F)|<h4>[^<>]*<\/h4>(*SKIP)(*F)|<h1>[^<>]*<\/h1>(*SKIP)(*F)|<h3>[^<>]*<\/h3>(*SKIP)(*F)|<h2>[^<>]*<\/h2>(*SKIP)(*F)|<b>[^<>]*<\/b>(*SKIP)(*F)|<a\b[^>]*>.*?</a>(*SKIP)(*F)|(\b'.$to.'\b)(?=[^>]*(?:<|$))!';
    $to = array(
        '/please/' => ' <a href="https://google.com">please</a> ',
        '/love/' => ' <a href="https://wordpress.org">love</a> ',
        '/Ask/' => ' <a href="https://wordpress.stackexchange.com/questions/ask">Ask</a> ',
    );
    $text = preg_replace( array_keys($from), $to, $text, 2 );
     }

    return $text;

}
add_filter('the_content', 'wp_affiliate_links');

Please Gurus Help me out, I have really tried my best

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.