more tag hack (1 post)

  1. ntoni1987
    Posted 6 years ago #

    Hi all!
    I have expirenced some problems while using the "more tag" feature of wordpress 2.5. Specifically, it happens that when I want to use the "more" feature to divide this text:

    some text
    other text

    wordpress produces this output

    some text

    which obviously breaks my layout.
    A quirk trick to workaround this problem is this:

    Add this function somewhere in your function.php file (usually located in your own style's directory, under wp-content/themes/YOURLOOK/functions.php)

    function close_dangling_tags($html){
      #put all opened tags into an array
      preg_match_all("#<([a-z]+)( .*)?(?!/)>#iU",$html,$result);
      #put all closed tags into an array
      $len_opened = count($openedtags);
      for($i=0;$i < $len_opened;$i++) {
        if ($openedtags[$i]!="" && !in_array($openedtags[$i],$closedtags)){
          $html .= '</'.$openedtags[$i].'>';
      $len_closed = count($closedtags);
      for($i=0;$i < $len_opened;$i++) {
        if ($closedtags[$i]!="" && !in_array($closedtags[$i],$openedtags)){
          $html = '<'.$closedtags[$i].'>' . $html;
      return $html;

    And add this lines, where the more tag is causing you problem. You'll usually have to replace the <?php the_content(); ?> block with the following one, search and replace for it in the file wp-content/themes/YOURLOOK/index.php)

    old block

    <?php the_content(); ?>

    new block

    					    	$the_content_text = ob_get_contents();
    						echo close_dangling_tags($the_content_text); ?>

    It works. It would be very useful to build up a single plugin based on this hack, if you'd like to do it, then you're welcome!

    Best regards from Italy,

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 6 years ago by ntoni1987
  • This topic is not a support question
  • WordPress version: 2.5