Looking for a way to include/embed text from a file on a page so that the short codes are processed

I’m using WP as a CMS. I’ve got multiple pages that share the same header.

group 1 has header 1. group 2 has header 2. etc.

Read More

I’ve looked at these two plugins for a quick way to insert a combination of html and shortcodes.
http://wordpress.org/extend/plugins/wp-include-file/
http://wordpress.org/extend/plugins/post-snippets/

Both solutions are neat, but they do not process the short codes.

Example:

<div id="bugs2">

<a href="pack-rat/"><img class="size-full wp-image-214" title="ID Pack Rat" src="http://xyz.com/epm/wp-content/uploads/2011/01/ID-Pack-Rat-e1295503174487.jpg" alt="" width="75" height="75" /></a>
Pack Rat
<a href="pocket-gopher/"><img class="size-full wp-image-218" title="ID Pocket Gopher" src="http://xyz.com/epm/wp-content/uploads/2011/01/ID-Pocket-Gopher-e1295503138319.jpg" alt="" width="75" height="75" /></a>
Pocket Gopher
</div>

Does anyone know of an alternative way to embed or include this code from an external file (in an include folder on the server) and have the shortcodes processed?

Thanks!

Related posts

Leave a Reply

3 comments

  1. I have done this before with wp-include-file
    you need to edit the file called wp-include-file.php in the plugin`s directory
    look at line 144 and replace:

    return $content;
    

    with

    return do_shortcode($content);
    

    that`s it.

    hope this helps.

  2. Didn’t test it but rather than editing plugin file it might be more convenient to wrap its call in your own function and re-register shortcode. Something like this:

    function wp_include_file_with_shortcode( $atts ) {
    
        return do_shortcode( wp_include_file( $atts ) );
    }
    
    remove_shortcode( 'include' );
    add_shortcode( 'include', 'wp_include_file_with_shortcodes' );
    
  3. My plugin get-post should handle this. It allows you to include posts in other posts/pages and will go ahead and process plugins during this inclusion. It should allow for a little bit of recursion as well 🙂