Question

I am new to WordPress. I am trying to create a plugin. I'm using a static shortcode:

[SRPMGT id=12345]

And this shortcode can be placed in any page. I want to replace this shortcode with html content:

<div class="result"> Content to replace... </div>

Note: This shortcode can be placed in any page.

Please help me solve this. Thanks in advance.

Was it helpful?

Solution

function add_shortcode( $tag, $func )

is the core of what you need to know.

So insert into your functions.php:

function srpmgt_shortcode() { return ' Content to replace... '; }

add_shortcode('SRPMGT_id=12345', 'srpmgt_shortcode');

OTHER TIPS

Add the following code to functions.php file of your plugin

// [srpgmt id="id-value"]
function srpgmt_func( $atts ) {
    extract( shortcode_atts( array(
        'id' => 'something',        
    ), $atts ) );

    return '<div class="result"> Content to replace... </div>';
}
add_shortcode( 'srpgmt', 'srpgmt_func' );

As already mentioned in the comment, for further reading go to : http://codex.wordpress.org/Shortcode_API

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top