Home > CMS Tutorial > WordPress > body text

How to add confirmation dialog to WordPress post button

藏色散人
Release: 2020-04-13 17:08:17
forward
3145 people have browsed it

How to add confirmation dialog to WordPress post button

How to add a confirmation dialog box to the WordPress article publish button?

Have you ever accidentally clicked the publish button and published an article? If you use social plug-ins, the mistaken publication will be shared on social networks and may even be included by search engines. A piece of code in this article will effectively prevent misuse.

How to add confirmation dialog to WordPress post button

Add the following code to the functions.php file of your current theme:

// This is the confirmation message that will appear.
$c_message = 'Are you SURE you want to publish this post?';
 
function confirm_publish(){
 
global $c_message;
echo &#39;<script type="text/javascript"><!--
var publish = document.getElementById("publish");
if (publish !== null) publish.onclick = function(){
    return confirm("&#39;.$c_message.&#39;");
};
// --></script>&#39;;
}
add_action(&#39;admin_footer&#39;, &#39;confirm_publish&#39;);
Copy after login

After that, click the publish button and you will see the prompt as shown above, Can prevent misuse.

For more WordPress themes, please go to the WordPress Template column to download!

The above is the detailed content of How to add confirmation dialog to WordPress post button. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template