Forums

How to modify post content before output to blog (4 posts)

  1. codejak
    Member
    Posted 3 years ago #

    Hi all!

    I am setting up a blog where most/all of the post are excpected to contain an identical set of information. Since I would like to structure these pieces of information a bit in the output of each post - and alwas in identical fashion, I intend to write a plugin that does just that.

    Basically, it should recognize a couple of tags that I would use in all of my post, e.g.,

    [item1]MyContent[/item1]
    [item2]MyContent[/item2]
    ...
    etc.

    so as for the plugin to be able to parse the post's content and replace the tags with HTML-elements that would allow me to build the desired structure and add the desired formatting (via CSS).

    I have gotten as far as identifyfing the relevant hook

    add_filter('the_content', 'myFunction');

    and linking my stylesheet

    echo '<link type="text/css" rel="stylesheet" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/myPath/myStyleSheet.css" />' . "\n";.

    I am suspecting that I will have to retrieve

    $post->post_content

    to apply my modifications, but this is just a suspicion, since I have not been able to test anything yet.

    I am failing, however, to understand how I return my modified content (which I expect to be stored in a string variable after the above operations) to 'the loop' so that it will be output to screen.

    Can anyone give me the necessary spark of inspiration?

    TIA

    Matthias

  2. Michael Fields
    Theme Wrangler
    Posted 3 years ago #

    Check out the Shortcode API. I think it would be perfect for what you need to do. And a bit less work too!

  3. codejak
    Member
    Posted 3 years ago #

    Hi Michael,

    Looks like this is just what I need. I'll see if I can get it to work.

    Thanks!

    Matthias

  4. Michael Fields
    Theme Wrangler
    Posted 3 years ago #

    Matthias, You're welcome... best of luck, please let me know if you figure this out, I would love to see what you come up with :)

Topic Closed

This topic has been closed to new replies.

About this Topic