Title: shortcode on all blog posts
Last modified: August 22, 2016

---

# shortcode on all blog posts

 *  [atok2](https://wordpress.org/support/users/atok2/)
 * (@atok2)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/shortcode-on-all-blog-posts/)
 * Hi
 * I’ve seen different variations of this question here, but mine is a bit more 
   specific, so i would really appreciate if anyone can help me out.
 * I would like to add this:
    Latest articles [Shortcode] below all of my blog posts
   without using a plugin and without doing it manually.
 * I have tried several techniques i found on the internet with some code modifications
   but that resulted in crashing the website.
 * “I do not know how to code or use php” so if anyone can give me a piece of a 
   code that i could try that would be great 🙂
 * Thank you very much

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

 *  [WpMicro](https://wordpress.org/support/users/wpmicro/)
 * (@wpmicro)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/shortcode-on-all-blog-posts/#post-5415524)
 * You’d want to edit your theme’s functions.php file and use the filter “the_content”.
   The code to put at the end of the file would be something like this:
 *     ```
       function add_my_extra_content( $content ) {
       	$content .= '<p>Latest articles</p>';
       	$content .= '[shortcode]';
               return $content;
       }
   
       add_filter( 'the_content', 'add_my_extra_content' );
       ```
   
 *  Thread Starter [atok2](https://wordpress.org/support/users/atok2/)
 * (@atok2)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/shortcode-on-all-blog-posts/#post-5415526)
 * Thank you very much, this almost worked 🙂
 * your code works but when i replace the [shortcode] with the actual shortcode,
   it crashes, any ideas why ?
 * You can see here your code with the shortcode
 * _[ Moderator note: code fixed. Please wrap code in the backtick character or 
   [use the code button](http://codex.wordpress.org/Forum_Welcome#Posting_Code).]_
 *     ```
       function add_my_extra_content( $content ) {
       	$content .= '<p>Latest articles</p>';
       	$content .= '[ess_grid alias="Articles similaires" settings='{"max-entries":"4"}' special='related'][/ess_grid][ess_grid alias="Articles similaires" settings='{"max-entries":"4"}' special='related'][/ess_grid]';
               return $content;
       }
   
       add_filter( 'the_content', 'add_my_extra_content' );
       ```
   
 *  [WpMicro](https://wordpress.org/support/users/wpmicro/)
 * (@wpmicro)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/shortcode-on-all-blog-posts/#post-5415532)
 * Try replacing the line that adds the shortcode with this:
 *     ```
       $content .= '[ess_grid alias="Articles similaires" settings=\'{"max-entries":"4"}\' special=\'related\'][/ess_grid][ess_grid alias="Articles similaires" settings=\'{"max-entries":"4"}\' special=\'related\'][/ess_grid]';
       ```
   
 *  Thread Starter [atok2](https://wordpress.org/support/users/atok2/)
 * (@atok2)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/shortcode-on-all-blog-posts/#post-5415576)
 * Sorry to not get back to you, i had a small problem to fix
 * We are almost there, the code works but it is on posts and pages, How do i make
   them show up on only posts not pages, or even better on only certain categories“
   if it is not hard to do”
 * thank you very very very much
 *  [Trey](https://wordpress.org/support/users/ix3/)
 * (@ix3)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/shortcode-on-all-blog-posts/#post-5415629)
 * Hey atok I just put this together real quick so there’s probably a better way
   to do it, but for now this should work for you. In the “$included_cats” array
   you’d put the category id’s that you want to have the shortcode show up on.
 * [http://pastebin.com/AqLJPysQ](http://pastebin.com/AqLJPysQ)
 *  Thread Starter [atok2](https://wordpress.org/support/users/atok2/)
 * (@atok2)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/shortcode-on-all-blog-posts/#post-5415633)
 * thank you very much Trey, ill try this as soon as get home
 * just one question, to add the category id’s is this how i do that ?
 *  if ( $cat == $category->cat_ID ‘3’, ‘4’, ‘5’) {
 *  [Trey](https://wordpress.org/support/users/ix3/)
 * (@ix3)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/shortcode-on-all-blog-posts/#post-5415634)
 * On line 6 of that pastebin:
 *     ```
       $included_cats = array( 0, 2, 10 );
       ```
   
 * Replace the numbers with the category id’s you want the shortcode to show up 
   on.
 *     ```
       $included_cats = array( 3, 4, 5 );
       ```
   
 * That would work for 3 4 and 5. Say you wanted to add more you could do:
 *     ```
       $included_cats = array( 3, 4, 5, 10, 11 );
       ```
   
 * And so on.
 *  Thread Starter [atok2](https://wordpress.org/support/users/atok2/)
 * (@atok2)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/shortcode-on-all-blog-posts/#post-5415645)
 * thank you very much for taking your time to write this

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

The topic ‘shortcode on all blog posts’ is closed to new replies.

## Tags

 * [blog post](https://wordpress.org/support/topic-tag/blog-post/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 8 replies
 * 3 participants
 * Last reply from: [atok2](https://wordpress.org/support/users/atok2/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/shortcode-on-all-blog-posts/#post-5415645)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
