WordPress – Shorten Shortcode

On my forum (made in WordPress) I let users add copy to clipboard buttons so they can make code easier to copy. I am using a plugin for this meaning that when you are posting something on the forum and type this then it will make a copy to clipboard button:

[pw-clippy caption="Copy"]Text to Copy goes here[/pw-clippy]

I don’t really like users having to use the name of the plugin ‘pw-clippy’ when making these buttons so I am wondering if I can shorten it so instead you type something like:

Read More
[copytoclip caption="Copy"]Text to Copy goes here[/copytoclip]

or this would also be fine:

[copytoclip]Text to Copy goes here[/copytoclip]

This may have an easy solution but I am fairly new to WordPress and would like to learn more.

Thanks for any help.

Note: I am not sure if it is called shortcode but any knowledge on it would be appreciated 😀

Related posts

Leave a Reply

1 comment

  1. Untested but here goes:

    function copytoclip_shortcode( $atts, $content = null ){
        return do_shortcode('[pw-clippy caption="Copy"]' . $content . '[/pw-clippy]');
    }
    
    add_shortcode( 'copytoclip', 'copytoclip_shortcode' );
    

    Add this to functions.php, or even better as a standalone plugin file in your wp-content/plugins/ directory.