Add shortcode to the editor (4 posts)

  1. dtommy79
    Posted 3 years ago #


    How can I add shortcodes to the editor?

    I know there are plugins for that, but I'm interested in the code level solution. Do you know any tutorial for that?


  2. Andrew Bartel
    Posted 3 years ago #

    Hi Tommy,

    Use the do_shortcode() function. For example, if your shortcode was [showsomethinghere id="7"] you'd just do this:

    echo do_shortcode('[showsomethinghere id="7"]');

    If you want to track down what the actual shortcode does, find where whatever is generating it runs the add_shortcode() function.

  3. dtommy79
    Posted 3 years ago #

    Hi Andrew,

    Thanks for the answer. Sorry I wasn't clear. By "add to the editor" I meant how can I add a button to the editor that will insert my custom shortcode?

  4. Andrew Bartel
    Posted 3 years ago #

    Well, you can create a custom metabox that inserts things into the editor itself, which I haven't done unfortunately. If i was trying to write a shortcode insert script, I'd probably go this route.

    Or you can reference this codex entry about adding buttons to TinyMCE: http://codex.wordpress.org/TinyMCE_Custom_Buttons

    Let us know what you come up with and maybe we can help you troubleshoot.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.