views:

59

answers:

1

I'm writing a plugin that add's a page with a tag [deposit_page], that tag should be replaced with some php code.

this is what I have but it doesn't work, something I'm missing or doing wrong? or did I forgot something?

function deposit_page_content($content) {
 $deposit_page_content = "here will go the content that should replace the tags";//end of variable deposit_page_content
    $content=str_ireplace('[deposit_page]',$deposit_page_content,$content);
return $content;
}
add_filter("the_content", "deposit_page_content");

I just noticed I gave the same variable name to the content that should replace the tag, and the function itself, could this be a problem?

+1  A: 

WordPress has support for [square_bracket_shortcodes] built in.

See: http://codex.wordpress.org/Shortcode_API

Here is your simple example:

function deposit_page_shortcode( $atts ) {
    $deposit_page_content = "here will go the content that should replace the tags";
    return $deposit_page_content;
}

add_shortcode( 'deposit_page', 'deposit_page_shortcode' );

You can paste this into your active theme's functions.php file.

If you wanted attributes, like [my_shortcode foo=bar], you'd do, at the top of this function:

extract(shortcode_atts(array(
    'foo' => 'default foo',
    'example' => 'default example',
), $atts));

// Now you can access $foo and $example
Mark Jaquith