Ready to get started?Download WordPress


[resolved] Add PHP inclue within the post content (6 posts)

  1. Eos Rose
    Posted 3 years ago #

    I've got multiple posts with complex content displaying custom field groups. I've created a template php file with the standard display I need, but there doesn't seem to be an easy way to run a php include withing the content. It is really dire that I figure out how to do this or I'll be pulling my hair out trying to format each post manually.

    And, no, I can't just place the include above or below the content area.

    How can I get this to work in the content of my post:

    <?php include( TEMPLATEPATH . '/track1.php' ); ?>

  2. kfallman
    Posted 3 years ago #

    hmm.. maybe do a string replace on content ?
    $content = str_replace('*track1*',

  3. Eos Rose
    Posted 3 years ago #

    I'm not really familiar with that. Would that replace the content entirely? That's not really what I'm trying to do. At this point, I'm considering placing ALL content in custom fields and ignoring the content box entirely. If I can make shortcodes work in custom fields, that might be the easiest all the way around.

  4. Eos Rose
    Posted 3 years ago #

    P.S. I found a plugin that will display the text of an include, but won't run the actual PHP code within the include. Huh.

  5. racer x
    Posted 3 years ago #

    Try creating a shortcode in your functions file something like(not exactly):

    function track_replace() {
    include( TEMPLATEPATH . '/track1.php' );
    add_shortcode('track', 'track_replace');

    help: http://www.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/

    Then call it with [track] in our posts.

  6. Eos Rose
    Posted 3 years ago #

    That sounds promising. I'll give it a shot!

Topic Closed

This topic has been closed to new replies.

About this Topic