How would you do this basic WP plugin?

Rate this post

I’m starting to develop it and I realise it’s kind of tricky. I need to convert the shortcode

[helloworld] into <h1>"Hello World"</h1> 

and be able to change

"Hello World" from admin

Can someone point me on the right way?



You need create hellowrold as a shortcode.

function hellowrold_func( $atts ) {
    $a = shortcode_atts( array(
        'content' => 'Default content',
    ), $atts );

    return "<h1>{$a['content']}</h1>";
add_shortcode( 'hellowrold', 'hellowrold_func' );

Then you can use it like this and change text as you like from the content attribute.

[hellowrold content="Hello World"]

See Shortcode API for more details.

If you need to add this to a plugin, simply create a file with a header content like this:

 * Plugin Name: YOUR PLUGIN NAME

Add the code above below this header and put the file inside a folder in your plugins directory.

See Plugins Basics for more details.

Leave a Reply

Your email address will not be published.

Back to top button