Title: Custom Post Type Replace the_content() in loop
Last modified: August 19, 2016

---

# Custom Post Type Replace the_content() in loop

 *  [mic3000](https://wordpress.org/support/users/mic3000/)
 * (@mic3000)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/custom-post-type-replace-the_content-in-loop/)
 * Hi everyone,
    What is the best way for replace the_content() in the loop for 
   certain custom post type?
 * i wrote this code
 *     ```
       add_filter('the_content','the_content_filter');
       function the_content_filter($content) {
       global $post;
   
       if ( $post->post_type == 'my_custom_post' and is_single ( ) ) {
       $$content = get_template_part('ri_template/ri-single');
       } elseif ( $post->post_type == 'my_custom_post' and in_the_loop() ) {
       $content = get_template_part('ri_template/ri-loop');
       } else {
       return $content;
       }
   
       }
       ```
   
 * what is the best way for replace the_content()?
    Thanks in advance!

Viewing 1 replies (of 1 total)

 *  Thread Starter [mic3000](https://wordpress.org/support/users/mic3000/)
 * (@mic3000)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/custom-post-type-replace-the_content-in-loop/#post-2000102)
 * It is the right way?

Viewing 1 replies (of 1 total)

The topic ‘Custom Post Type Replace the_content() in loop’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [mic3000](https://wordpress.org/support/users/mic3000/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/custom-post-type-replace-the_content-in-loop/#post-2000102)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
