Title: Modify the Filter
Last modified: September 1, 2016

---

# Modify the Filter

 *  Resolved [ananzhe25](https://wordpress.org/support/users/ananzhe25/)
 * (@ananzhe25)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/)
 * I have the following code and I need help as my coding knowledge is basic. I 
   need to remove the filter and keep the if argument that if there is any attached
   images to the post to add it to the post. Because I want to add the code directly
   rather than call it from the theme function.
 *     ```
       add_filter( 'the_content', 'put_thumbnail_in_posting' );
       function put_thumbnail_in_posting( $content )
       {
           if ( 'advert' == get_post_type() )
           {
               $args = array(
                   'order'          => 'ASC',
                   'post_mime_type' => 'image',
                   'post_parent'    => get_the_ID(),
                   'post_status'    => null,
                   'post_type'      => 'attachment',
               );
   
               $attachments = get_children( $args );
   
               if ( $attachments ) {
                   $thumbnails = '';
                   foreach( $attachments as $attachment )
                   {
                       $thumbnails .= wp_get_attachment_image( $attachment->ID, $size = null, $icon = true, array(
                           'style' => 'float:left;margin:15px;'
                       ) );
                   }
                   $content = $thumbnails . $content;
               }
           }
           return $content;
       }
       ```
   

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663874)
 * Hi ananzhe25
 * It’s not really clear what it is you want to do.
 * Remove the filter from your functions.php file and add the thumbnails in theme
   template files directly?
    [https://developer.wordpress.org/themes/basics/template-files/](https://developer.wordpress.org/themes/basics/template-files/)
 * Or something else?
 *  [Digico Paris](https://wordpress.org/support/users/digico-paris/)
 * (@digico-paris)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663880)
 * on workaround it would work like this in functions.php of your your theme:
 * add_filter( ‘the_content’, ‘put_thumbnail_in_posting’ );
    function put_thumbnail_in_posting(
   $content ) { if ( ‘advert’ == get_post_type() ) { $args = array( ‘order’ => ‘
   ASC’, ‘post_mime_type’ => ‘image’, ‘post_parent’ => get_the_ID(), ‘post_status’
   => null, ‘post_type’ => ‘attachment’, );
 *  $attachments = get_children( $args );
 *  if ( $attachments ) {
    $thumbnails = ”; foreach( $attachments as $attachment){
   $thumbnails .= wp_get_attachment_image( $attachment->ID, $size = null, $icon 
   = true, array( ‘style’ => ‘float:left;margin:15px;display:none;’
 *  style => ng-controller-list ) );
    } $content = $thumbnails . $content; } } return
   $content; }lie this, you will be able to use angular js simple example
 *  Thread Starter [ananzhe25](https://wordpress.org/support/users/ananzhe25/)
 * (@ananzhe25)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663891)
 * Thank you for all the replies,
 * I am trying to move the code from function.php to single-post.php and get the
   same results.. I hope this is more clear.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663914)
 * Remove the filter and function from your theme’s functions.php file
    And put 
   this in your single-post.php (or single-advert.php) file.
 *     ```
       <?php
       	$args = array(
       		'order'          => 'ASC',
       		'post_mime_type' => 'image',
       		'post_parent'    => get_the_ID(),
       		'post_status'    => null,
       		'post_type'      => 'attachment',
       	);
   
       	$attachments = get_children( $args );
   
       	if ( $attachments ) {
       		$thumbnails = '';
       		foreach ( $attachments as $attachment ) {
       			$thumbnails .= wp_get_attachment_image( $attachment->ID, $size = null, $icon = true, array(
       					'style' => 'float:left;margin:15px;'
       				) );
       		}
       		echo $thumbnails;
       	}
       ?>
       ```
   
 * [https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post](https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post)
 *  Thread Starter [ananzhe25](https://wordpress.org/support/users/ananzhe25/)
 * (@ananzhe25)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663926)
 * keesiemeijer Thank you so much! I appreciate it.
 *  Thread Starter [ananzhe25](https://wordpress.org/support/users/ananzhe25/)
 * (@ananzhe25)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663927)
 * How to seclude this result for custom post ‘advert’ only?
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663934)
 * The `single-post.php` file is only used for single posts.
 * Where do you want to exclude (or include) custom post type `advert` posts?
 *  Thread Starter [ananzhe25](https://wordpress.org/support/users/ananzhe25/)
 * (@ananzhe25)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663935)
 * The default is single-advert.php but I need to use the code in a third party 
   plugins where the code need to load the attached images if any attached to the
   custom post ‘advert’
 * The custom posts ‘advert’ is already included in my latest posts. What I need
   is the code to look for advert posts only and return any attached images.
 * I think that what the `if ( 'advert' == get_post_type() )` meant to do
 *  Thread Starter [ananzhe25](https://wordpress.org/support/users/ananzhe25/)
 * (@ananzhe25)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663937)
 * Here what my testing gave me
 *     ```
       <?php
       if ( 'advert' == get_post_type() )
           {
               $args = array(
                   'order'          => 'ASC',
                   'post_mime_type' => 'image',
                   'post_parent'    => get_the_ID(),
                   'post_status'    => null,
                   'post_type'      => 'attachment',
               );
   
               $attachments = get_children( $args );
   
               if ( $attachments ) {
                   $thumbnails = '';
                   foreach( $attachments as $attachment )
                   {
                       $thumbnails .= wp_get_attachment_image( $attachment->ID, $size = null, $icon = true, array(
                           'style' => 'float:left;margin:1px;'
                       ) );
                   }
   
               }
           }
          echo $thumbnails;
       ?>
       ```
   
 * It seems working
 *  Thread Starter [ananzhe25](https://wordpress.org/support/users/ananzhe25/)
 * (@ananzhe25)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663940)
 * Thank you! keesiemeijer
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663948)
 * Ha. You solved it yourself!
 * Very good 🙂

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Modify the Filter’ is closed to new replies.

## Tags

 * [custom post](https://wordpress.org/support/topic-tag/custom-post/)
 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 3 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/modify-the-filter/#post-7663948)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
