The goal is to reuse some part of code to login and logout user in ajax with or without reload page .

I can't call the content of php file ajax_user.php inside wordpress template directory from my plugin and it wp_ajax function (to login and logout user).

I tried these functions inside my wp_ajax function handle_user_login():

$resumeaccount = get_template_part( 'ajax_user') ;

$resumeaccount = include get_template_directory() . '/ajax_user.php' ;

My content inside ajax_user.php :

<?php echo'<div id="isconnecteddisplaylogout"><p> Connected</p><form id="atv_user_logout" method="post" action="atv_user_logout"><button id="disconnect"  type="submit" class="logout">Sign out?></button></form></div>';?>

I tried without echo , without singlequote and wihtout <?php for this ajax_user.php file. Nothing change

Using include get_template_directory() json data return object : [1]

the content of ajax_user.php work well if I insert it directly inside variable $resumeaccount : without to try to call php file from template directory

I can't define if my issue come from syntaxe or function get_template_directory().

1 Answer 1


I resolved my issue. My error came from both calling the php file from the wordpress theme and converting the html code to an object value so that jquery ajax interprets it as it should.

$tmpdir = get_template_directory() . '/ajax_user.php';
$resumeaccount = file_get_contents($tmpdir);

So I get Html content inside singles quote (value object) instead of directly interpreting the html code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.