WordPress.org

Ready to get started?Download WordPress

Forums

simple guide to create custom tag (6 posts)

  1. devoue
    Member
    Posted 7 years ago #

    Hello,

    I'm looking for a tutorial explaining the process of creating a custom taf on wordpress.

    I'd like to render some custom html from a simple tag
    example :

    <music id='14' />

    which will render :

    <embed object flashMusicPlayer.swf source="14.mp3" .....>
    </embed>

    The code rendering the html is already done in my function
    getMusicCode (int $idMusic), in my php code

    I just need to know where to implement the filtering of the wordpress content to call my custom function

    thanks a lot if you have info

  2. devoue
    Member
    Posted 7 years ago #

    note : I'm using WordPress 2.0

  3. devoue
    Member
    Posted 7 years ago #

    anyone ?

  4. Kafkaesqui

    Posted 7 years ago #

    Take a look at my My Tags plugin. It doesn't allow for unique attributes (i.e. id='14'), but with some mods one could get it to handle them:

    http://wordpress.org/support/topic/32984#post-186878

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    I just need to know where to implement the filtering of the wordpress content to call my custom function

    You can implement it almost anywhere you like, actually. Preferably in a plugin or in functions.php or something. Before your Loop executes, anyway.

    function your_function($content)
    {
    // $content contains the content of the actual post
    // you can modify content all you like and return it,
    // and that's how it's modified
    return $content;
    }
    // this adds your filter into the_content chain, so
    // that every post's content will get passed into
    // your function
    add_filter('the_content','your_function');

    A simple example:
    function add_giggity($content) {
    return $content." Giggity!";
    }
    add_filter('the_content','add_giggity');

    For your particular case, you'll probably want to have your function do a regexp match on the incoming content and replace that text with your embed text as appropriate. I'd look into the preg_match and preg_replace PHP functions if I were you. Very handy.

  6. devoue
    Member
    Posted 7 years ago #

    thanks guys

Topic Closed

This topic has been closed to new replies.

About this Topic