WordPress.org

Support

Support » Plugins and Hacks » wordpress replace content of a page (plugin)

wordpress replace content of a page (plugin)

  • 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?

Viewing 1 replies (of 1 total)
  • You should use the WordPress shortcode API.

    add_shortcode('deposit_page', 'deposit_page_shortcode');
    
    function deposit_page_shortcode( $attr, $content ) {
    	// $attr is an array of $key=>$value pairs
    	// $content is a string containing the enclosed content
    	// ... do something with $attr and $content
    	// return the expected result
    }

Viewing 1 replies (of 1 total)
  • The topic ‘wordpress replace content of a page (plugin)’ is closed to new replies.
Skip to toolbar