How do you add a custom tab to Wordpress post edit

2019-06-03 22:57发布

At the moment there are two tabs in the post editor Visual and HTML.

Is there a hook that allows for another tab to be added?

If so, what is it?

Additional info:

So, let's say the content of the post is an address.

The additional tab will contain the form for the person to fill in. When the post is updated, the person's answers will be stored as the post content. (pre-formatted with a template created by me)

标签: php wordpress
2条回答
Melony?
2楼-- · 2019-06-03 23:03

This is how the HTML and Visual controls can control the editor view:

            $('a.toggleVisual').click(
                function() {
                    tinyMCE.execCommand('mceAddControl', false, id);
                }
            );

            $('a.toggleHTML').click(
                function() {
                    tinyMCE.execCommand('mceRemoveControl', false, id);
                }
            );

        });

You see that basically, the difference between the two views is just adding or removing controls to leave the raw HTML view or to transform it. But you could add a button just beside. This is the code I use myself to display the tabs:

 <p align="right"><a class="button toggleVisual">Visual</a><a class="button toggleHTML">HTML</a></p><textarea rows="10" class="foo" id="editorid" name="editorname" style="width:100%%;">Text area content</textarea>

So you could just add another tab like this:

<p align="right"><a class="button toggleTemplate">Your Template Tab</a><a class="button toggleVisual">Visual</a><a class="button toggleHTML">HTML</a></p><textarea rows="10" class="foo" id="editorid" name="editorname" style="width:100%%;">Text area content</textarea>

And then bind to the click event to display another view, generated by your own routine...

查看更多
时光不老,我们不散
3楼-- · 2019-06-03 23:11

No. There is no hook to do this. But note that the two tabs (HTML and Visual) are treated differently than the rest of the TinyMce buttons (which can be set through options). Visual and HTML tabs can even be placed beside the editor and controlled with JavaScript to produce the same effect on the editor (switch its view from HTML to text and vice and versa).

查看更多
登录 后发表回答