Why my custom function being called twice in WordPress?
For instance i have this function in functions.php:
function your_function_name() {
if(isset($_POST['your_var'])) {
// return $error;
echo '<p class="alert alert-danger"><span class="close" data-dismiss="alert">×</span> Work NOT submitted! Please correct the error(s) below.</p>';
}
}
My template:
<?php
your_function_name();
?>
<form class="form-submission" method="post" action="">
<input type="text" class="form-control" placeholder="Name" name="your_var">
...
When the form is submitted, I get this <p class="alert alert-danger"><span class="close" data-dismiss="alert">×</span> Work NOT submitted! Please correct the error(s) below.</p>
twice on my screen. One is before the html tag and other one is on the correct location:
<p class="alert alert-danger"><span class="close" data-dismiss="alert">×</span> Work NOT submitted! Please correct the error(s) below.</p><!DOCTYPE html>
<html lang="en-US" class="no-js">
<head>
....
<p class="alert alert-danger"><span class="close" data-dismiss="alert">×</span> Work NOT submitted! Please correct the error(s) below.</p>
<form class="form-submission" method="post" action="">
<input type="text" class="form-control" placeholder="Name" name="your_var">
...
The first one before the html tag should not exist but it does! Why? How can I fix this?
I want the message appear before the form tag not before the html tag.
Following this guide, just put my code before:
Then the problem solved.