1

I want to remove all links on my custom fields.

My fields for now :

<li><a href="">my item</a></li>

and I'm trying to get this:

<li>my item</li>

This is the code I tried, but it isn't working for me.

function wpse_227315_strip_hyperlinks( $content ) {
    preg_match_all( '!<a[^>]*? href=[\'"]#[^<]+</a>!i', $content, $matches );

    foreach ( $matches[0] as $link )
        $content = str_replace( $link, strip_tags( $link ), $content );

    return $content;
}

add_filter( 'acf/load_value/name=artist', 'wpse_227315_strip_hyperlinks' );
2
  • 1
    Why don't you go to the original code that is making the link and remove it from the list items at the source? – rudtek Mar 2 '17 at 18:34
  • well suggestion from @rudtek additionally are you sure that the action hook acf/load_value/name=artist exists? – Anwer AR Mar 2 '17 at 18:52
0

Have you try too remove all tag from content then add li ?

$content = '<li>'.strip_tags(get_field('artist')).'</li>';
1
  • thanks for your answer i tried, isn't working for me.There is no other way ? any thinks – alam7o Mar 3 '17 at 0:39

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.