javascript - wrapping pulled text in <p> tags -
i have wordpress site have pulled out images , text separately use in different parts on single.php.
html - (bootstrap 3 framework)
<div class="row"> <div class="col-md-12"> <?php preg_match_all('/(<img [^>]*>)/', get_the_content(), $matches); for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) { echo $matches[1][$i]; } ?> </div> </div><!-- /row --> <div class="row"> <div class="col-md-12"> <?php echo preg_replace('/(<img [^>]*>)/', '', get_the_content()); ?> </div> </div><!-- /row -->
this puts images in first row, , text in second row.
however, not wrap text when it's pulled out in tags. want wrap text in < p > tag can apply css it.
also, in browser's inspector, pulls href link of image , pastes in code doesn't show picture. (the first row/code, pulls same link , shows picture) not sure if thats normal or not.
what solid_luffy described okay can go simpler. can add <p>
tags before , after text gets echoed.
<div class="col-md-12"> <p> <?php echo preg_replace('/(<img [^>]*>)/', '', get_the_content()); ?> </p> </div>
the upside approach decouples page styling actual content, practice.
Comments
Post a Comment