检查数据库后,如何在wordpress functions.php文件中添加javascript
如何在此代码中在wordpress functions.php文件中添加内联javascript检查数据库后,如何在wordpress functions.php文件中添加javascript,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,如何在此代码中在wordpress functions.php文件中添加内联javascript function jointheclubfbconnect(){ $message = ' <div style="width:600px;background:white;padding:25px;"> <div style="width:100%;font-size:25px;"></div> <br/> $mes
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' . "\r\n";
$header .= "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type:text/html;charset=utf-8" . "\r\n";
$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' );
}
函数jointheclubfbconnect(){
$message='1
$message.=“亲切问候
团队
”;
$header='From:Teen |info@teen.com“。”\r\n”;
$header.=“MIME版本:1.0”“\r\n”;
$header.=“内容类型:text/html;字符集=utf-8”。\r\n”;
$frominfo@teen.com';
$subject='感谢您加入青少年';
$fbemail=$_POST['fbemail'];
全球$wpdb;
$checkUserEmail=$wpdb->get_结果(“选择*来自俱乐部_成员,其中Email='”“$fbemail.”);
//var_dump($checkUserEmail);
$ip=$_POST['ip'];
$to='';
$to.=$fbemail;
if(空($checkUserEmail)){
if(邮件($to、$subject、$message、$header)){
回声‘ok’;
全球$wpdb;
$wpdb->insert(
“俱乐部成员”,
排列(
“Email”=>fbemail美元,
“IP”=>$IP,
'日期'=>当前时间('d M Y H:i:s')
),
数组(
“%s”,
“%s”,
“%s”
)
);
}
}否则{
echo“你已经注册了”;
函数print_my_inline_script(){
如果(wp_脚本_是('jquery','done')){
?>
警报(“是”);
警报(“是”);
让脚本排队的正确方法
<?php
function _adding_scripts() {
wp_register_script('my_custom_script', get_template_directory_uri() . '/js/custom_script.js', array('jquery'),'1.1', true);
wp_enqueue_script('my_custom_script');
}
add_action( 'wp_enqueue_scripts', '_adding_scripts' );
?>
对于functions.php
中的内联脚本,需要在文档准备就绪或jQuery(document.ready()
loadjQuery(window.load())时调用脚本/代码
@noman的内联解决方案不适用于@Anahit DEV,因为它应该是:
function print_my_inline_script_custom() {
echo '<script type="text/javascript">
// Document ready
jQuery(document).ready(function(){
alert("call");
});
</script>';
}
add_action( 'wp_footer', 'print_my_inline_script_custom' );
function print\u my\u inline\u script\u custom(){
回声'
//文件准备就绪
jQuery(文档).ready(函数(){
警报(“呼叫”);
});
';
}
添加动作('wp_footer'、'print_my_inline_script_custom');
函数调用与操作挂钩名称不对应。您的问题不清楚。您可以在Wordpress中编辑functions.php,但从技术上讲,这不是所谓的“内联”function.Inline函数将被添加到主题更新中的某个位置的块中。那么你的意思是什么?我不太明白你当前面临的问题是什么。我的问题是functions.php中的脚本不起作用。我如何才能在代码的其他状态下使用js的某些行?这在我的函数中不起作用。我将在外部而不是内部工作wp函数。@AnahitDEV你什么意思我将在wp函数外部工作而不是在wp函数内部工作
?
jQuery(document).ready(function(){
alert('call');
});
<?php
function print_my_inline_script_custom() {
echo '<script type="text/javascript">
// Document ready
jQuery(document).ready(function(){
alert("call");
});
// OR window load
jQuery(window).load(function(){
alert("call");
});
</script>';
}
add_action( 'wp_footer', 'print_my_inline_script' );
function print_my_inline_script_custom() {
echo '<script type="text/javascript">
// Document ready
jQuery(document).ready(function(){
alert("call");
});
</script>';
}
add_action( 'wp_footer', 'print_my_inline_script_custom' );