Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1928410
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:58:29+00:00 2026-05-17T06:58:29+00:00

I ran into a slight coding problem with WordPress template. This is the code

  • 0

I ran into a slight coding problem with WordPress template. This is the code I use in template:

<?php echo teaser(40); ?>

In my functions, I use this to strip tags and get content from allowed tags only.

<?php
function teaser($limit) {
    $content = explode(' ', get_the_content(), $limit);
    if (count($content)>=$limit) {
    array_pop($content);
    $content = implode(" ",$content).'...';
    } else {
    $content = implode(" ",$content);
    }   
    $content = preg_replace('/\[.+\]/','', $content);
    $content = apply_filters('the_content', $content); 
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = strip_tags($content, '<p><a><ul><li><i><em><strong>');
    return $content;
}
?>

The problem: I use the above code to strip tags from the content, but WordPress already puts image tags within paragraph. So the result is empty paragraph tags where images are stripped.

Just for the sake of cleaning up my code and useless empty tags.
My question is how to remove empty paragraph tags?

<p></p>

Thanks a lot in advance! 🙂

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:58:30+00:00Added an answer on May 17, 2026 at 6:58 am

    use this regex to remove empty paragraph

    /<p[^>]*><\\/p[^>]*>/
    

    example

    <?php
    $html = "abc<p></p><p>dd</p><b>non-empty</b>"; 
    $pattern = "/<p[^>]*><\\/p[^>]*>/"; 
    //$pattern = "/<[^\/>]*>([\s]?)*<\/[^>]*>/";  use this pattern to remove any empty tag
    
    echo preg_replace($pattern, '', $html); 
    // output
    //abc<p>dd</p><b>non-empty</b>
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ran into a strange problem in PHP today and I'm wondering if someone can
I ran into this problem at my old job, and now again at my
Possible Duplicate: ASP.Net and GetType() I ran into a slight problem today. As you
I ran into this code on Wikipedia : (define (pyth x y k) (*
I ran into a little problem. I am creating a web app with code
Ran into this problem today, posting in case someone else has the same issue.
ran into a problem this morning. I wrote the following lines: var Markup =
I ran into this problem when I try to solve a partial differential equation.
Ran into this error message while trying to select some records off a table.
I ran into a problem using Springsource Tool Suite when writing some groovy scripts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.