简体   繁体   中英

Wordpress - How to add a button into a Wordpress' post and make it work?

I've just started writing plugins on Wordpress and I'm struggling with adding a small button on every post that helps translate the whole post into another language. I tried to get the post's content, then add a button into it and return. But this certainly seems very bad. Can anybody think of a different way of doing this?

And (say) if I successfully place a button on a post, how can I make it performs its function when users click on it?

Thank you.

Adding a button to every post can be done using the appropriate action: for what you want to do see the *edit_post* action (at http://codex.wordpress.org/Plugin_API/Action_Reference ). You should be able to add your button's content to the end of the post. Alternatively you might need to modify the theme to add the buttons (if you don't want to modify the post content).

As far as performing its function, if you're familiar with jQuery you can attach an event listener to the button you insert into the post that performs the actual functionality. You can make an ajax callback to your plugin as described here: http://codex.wordpress.org/AJAX_in_Plugins .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM