How can I add inline javascript in wordpress functions.php file within this code
function jointheclubfbconnect(){
$message = '
<div style="width:600px;background:white;padding:25px;">
<div style="width:100%;font-size:25px;"></div>
<br/>
$message .='<div style="width:100%;display:block;color:#666666;">Kind regards</div><br/><div style="width:100%;display:block;color:#666666;">Team</div><br/><img src="'.get_bloginfo('url') .'/wp-content/themes/teenvoice/images/smalllogoteenvoice.png" alt="Logo"><br/>';
$header = 'From: Teen | info@teen.com' . "rn";
$header .= "MIME-Version: 1.0" . "rn";
$header .= "Content-type:text/html;charset=utf-8" . "rn";
$from = 'info@teen.com';
$subject = 'Thank You for Joining Teen';
$fbemail = $_POST['fbemail'];
global $wpdb;
$checkUserEmail = $wpdb->get_results("SELECT * FROM club_members WHERE Email = '".$fbemail."'");
// var_dump($checkUserEmail);
$ip = $_POST['ip'];
$to = '';
$to .= $fbemail;
if(empty($checkUserEmail)){
if(mail($to, $subject, $message, $header)) {
echo 'ok';
global $wpdb;
$wpdb->insert(
'club_members',
array(
'Email' => $fbemail,
'IP' => $ip,
'Date' => current_time('d M Y H:i:s')
),
array(
'%s',
'%s',
'%s'
)
);
}
}else{
echo 'You already Registered';
function print_my_inline_script() {
if ( wp_script_is( 'jquery', 'done' ) ) {
?>
<script type="text/javascript">
alert('Yesss');
</script>
<?php
}
}
add_action( 'wp_footer', 'print_my_inline_script' );
}
}
I have tried doing the following
function print_my_inline_script() {
if ( wp_script_is( 'jquery', 'done' ) ) {
?>
<script type="text/javascript">
alert('Yesss');
</script>
<?php
}
}
add_action( 'wp_footer', 'print_my_inline_script' );
You can see this in the code but it didnt work.How I can add 2 lines of jquery within my code?
@noman’s inline solution didnt work for @Anahit DEV because it should be:
The function call was not corresponding the action hook name.
Proper way to enqueue your script.
custom_script.js
file contains below code.For inline script in
functions.php
you need to call your script/code when document ready orjQuery(document).ready()
loadjQuery(window).load()