Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // THIS ONE IN THE THEME'S FUNCTIONS
- function remove_first_image($the_string) {
- $count = substr_count($the_string, '<img');
- if ($count > 0) {
- $length = strlen($the_string);
- $imgBeg = strpos($the_string, '<img');
- $imgEnd = strpos($the_string, '>', $imgBeg);
- $chop = $length-$imgEnd;
- $new_content = substr($the_string, 0, $imgBeg) . substr($the_string, $imgEnd+1, $chop);
- $capcount = substr_count($new_content, '[caption');
- if ($capcount > 0) {
- $length = strlen($new_content);
- $capBeg = strpos($new_content, '[caption');
- $capClose = strpos($new_content, '/caption]');
- $capEnd = strpos($new_content, ']', $capClose);
- $chop = $length-$capEnd;
- $final_content = substr($new_content, 0, $capBeg) . substr($new_content, $capEnd+1, $chop);
- return $final_content;
- }
- else {
- return $new_content;
- }
- }
- else {
- return $the_string;
- }
- }
- ?>
- <?php
- // CALLING THE FUNCTION FROM THE LOOP
- ?>
- <?php while ( have_posts() ) : the_post(); ?>
- <?php $old_content = get_the_content(); ?>
- <?php $new_content = remove_first_image($old_content); ?>
- <?php $display_content = apply_filters('the_content',$new_content); ?>
- <div class="your-content-class">
- <?php echo $display_content; ?>
- </div>
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement