Find and change URLs in content

Question

I have found a solution to change links in my wordpress theme, but not the links in the content. How is it possible to get the URL in the content, so I can also changed them?

I need to use the content filter. But how is it possible to change URLs like apple.com/test/ apple.com/test-123/, apple.com, microsoft.com, microsoft.com/test/

add_filter('the_content ', 'function_name');

The answer of a similiar question unfortunately doesn’t work.

This is my working solution to change links, but not the links in the content.

add_filter('rh_post_offer_url_filter', 'link_change_custom');
function link_change_custom($offer_post_url){

$shops= array(
        array('shop'=>'apple.com','id'=>'1234'),
        array('shop'=>'microsoft.com','id'=>'5678'),
        array('shop'=>'dell.com','id'=>'9876'), 
    );
    foreach( $shops as $rule ) {
        if (!empty($offer_post_url) && strpos($offer_post_url, $rule['shop']) !== false) {      
            $offer_post_url = 'https://www.network.com/promotion/click/id='.$rule['id'].'-yxz?param0='.rawurlencode($offer_post_url);
}    
    }
0
, , Grischa 3 years 2020-03-28T16:52:11-05:00 0 Answers 125 views 0

Leave an answer

Browse
Browse