Skip to main content
corrected the regex
Source Link
Minh Tri
  • 3.4k
  • 3
  • 24
  • 45

MaybeSuppose you haven't modified anything to change the default content output, maybe this can help:

add_filter('the_content', function($content)
{
  $content = preg_replace('~^<p><img([^>]+)></p>~i', '', $content, 1);

  return $content;
}, PHP_INT_MAX);

Maybe this can help:

add_filter('the_content', function($content)
{
  $content = preg_replace('~^<p><img([^>]+)></p>~i', '', $content, 1);

  return $content;
}, PHP_INT_MAX);

Suppose you haven't modified anything to change the default content output, maybe this can help:

add_filter('the_content', function($content)
{
  $content = preg_replace('~^<p><img([^>]+)></p>~i', '', $content, 1);

  return $content;
}, PHP_INT_MAX);
added 62 characters in body
Source Link
Minh Tri
  • 3.4k
  • 3
  • 24
  • 45

YouMaybe this can try to match all images in post content and remove the first onehelp:

add_filter('the_content', function($content)
{
  $content = preg_match_allpreg_replace('/<img'~^<p><img([^>]+)>></i'p>~i', '', $content, $matches1);

    return str_replace($matches[0][0], '', $content);$content;
}, PHP_INT_MAX);

You can try to match all images in post content and remove the first one:

add_filter('the_content', function($content)
{
    preg_match_all('/<img([^>]+)>/i', $content, $matches);

    return str_replace($matches[0][0], '', $content);
}, PHP_INT_MAX);

Maybe this can help:

add_filter('the_content', function($content)
{
  $content = preg_replace('~^<p><img([^>]+)></p>~i', '', $content, 1);

  return $content;
}, PHP_INT_MAX);
Source Link
Minh Tri
  • 3.4k
  • 3
  • 24
  • 45

You can try to match all images in post content and remove the first one:

add_filter('the_content', function($content)
{
    preg_match_all('/<img([^>]+)>/i', $content, $matches);

    return str_replace($matches[0][0], '', $content);
}, PHP_INT_MAX);