0

I'm trying to insert some custom code in each post in Wordpress, provided that it complies wit certain conditions. My problem is that the content needs to be added in an specific location that is not the top or the bottom. I know the HTML structure of the posts, since all follow a pattern.

I'm guessing that I can use a filter, but I don't know how to actually access and modify the part I want. This is how the structure looks before the modification:

<div class="primary-content">
    <div class="lesson-left cf">
        ...My Content here
    </div>
</div>

...and this is how I want it to look afterwards:

<div class="primary-content">
    <div class="lesson-left cf">
        ...My Content here
    </div>
    <div class="lesson-right">
        ...more content here, added dynamically
    </div>
</div>

[EDIT]

To provide a better idea, this is how the code in the template looks (only the relevant part):

<div class="lesson-page cf">
    <?php the_content() ?>
    <div class="lesson-right">
        <ul class="lesson-right lesson-button navigation">
            <?php if(get_post_meta( $post->ID, '_pdf_lesson_version', true )) { ?>
                <li class="save"><a href='<?php echo get_post_meta( $post->ID, '_pdf_lesson_version', true ) ?>'>SAVE LESSON</a></li>
            <?php } ?>
            <?php if(get_post_meta( $post->ID, '_word_lesson_version', true )) { ?>
                <li class="customize"><a href='<?php echo get_post_meta( $post->ID, '_word_lesson_version', true ) ?>'>CUSTOMIZE LESSON</a></li>
            <?php } ?>
            <li class="facebook-share">
                <div class="fb-share-button" data-href="<?php echo get_the_permalink() ?>" data-width="200" data-type="button"></div>
            </li>
        </ul>
    </div>
</div>

Everything inside the <ul class="lesson-right lesson-button navigation"></ul> I need to move into the content of the post. It is outside now, but needs to be contained in the content structure.

[/EDIT]

Any help is appreciated. Thank you for taking the time to read.

  • 2
    How does your PHP structure look? Could you just add it after <?php the_content(); ?> is called? – Howdy_McGee Aug 29 '14 at 17:26
  • Hi @Howdy_McGee. I updated the question to include what you requested. If more clarifications are needed, just tell me. Thanks for your interest. – reydelleon Aug 29 '14 at 17:45
  • 2
    If you need to move UL into the_content(), could you just move it right under the_content()? – Howdy_McGee Aug 29 '14 at 17:57
  • You should use a shortcode. Create a basic shortcode that does the queries you need (eg. get_post_meta()) and then you can place that shortcode anywhere in the content. – gdaniel Aug 29 '14 at 18:07
  • 1
    Both the the_content filter, for appending or prepending, and how to make use of the Shortcode API, if you need to put your extra content anywhere in the post, are the topic of multiple threads on here. I suggest you do a research, I'm sure you will find what you need. Good luck! – Nicolai Aug 29 '14 at 18:12
0

Finally, I had to add the required code inside another shorcode I had in place to create the content structure. That way I avoided creating an extra shorcode and was able to put the custom code in the exact position I wanted.

Thanks to all those who helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.