wordpress replace content of a page (plugin) (2 posts)

  1. krike
    Posted 5 years ago #

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

  2. Pete Mall
    Posted 5 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic