Version: 1.2.1 (Core & Pro)
Last Updated: November 2025
Difficulty: Advanced
Time Required: 20 minutes
Overview
Instead of using shortcodes in page content, you can embed login forms directly into your theme’s PHP template files. This is useful for custom headers, footers, sidebars, or specialized page templates.
Why Embed in Theme Files?
Use Cases
✓ Custom Page Templates
Build unique login page layouts not achievable with standard pages.
✓ Theme Header/Footer
Add login forms to navigation menus or footer widgets.
✓ Conditional Display
Show/hide login forms based on complex PHP logic.
✓ Advanced Customization
Combine with other PHP functions and theme features.
Basic PHP Function
Display Login Form
Function:
<?php attributes_login_form(); ?>
With parameters:
<?php attributes_login_form(array(
'redirect' => '/dashboard/',
'label_submit' => 'Sign In'
));
?>
Function Parameters
Available Arguments
All shortcode parameters work as function arguments:
<?php $args = array(
'redirect' => '/member-dashboard/',
'redirect_on_logout' => '/goodbye/',
'form_id' => 'header_login',
'label_username' => 'Email Address',
'label_password' => 'Your Password',
'label_remember' => 'Keep me logged in',
'label_submit' => 'Login Now',
'label_lost_password' => 'Forgot password?',
'value_remember' => 'true'
);
attributes_login_form($args);
?>
Common Implementation Examples
Example 1: Custom Page Template
File: page-login.php (in your theme folder)
<pre><code class="language-php">
<?php /**
* Template Name: Custom Login Page
*/
get_header(); ?>
<div class="custom-login-page">
<div class="login-container">
<div class="login-welcome">
<h1>Welcome to <?php bloginfo('name'); ?></h1>
Login to access your account
</div>
<div class="login-form-container">
<?php attributes_login_form(array(
'redirect' => home_url('/dashboard/'),
'label_submit' => 'Access Your Account'
));
?>
</div>
<div class="login-help">
<p>Need help? <a href="/%3C?php%20echo%20home_url(%27/support/%27);%20?%3E">Contact Support</a>
</p></div>
</div>
</div>
<?php get_footer(); ?>
Create the template:
- Save above code as
in your theme
<ul>
<li>Create new page in WordPress</li></ul>
<ul>
<li>Select "Custom Login Page" template</li></ul>
<ul>
<li>Publish page</li></ul>
<h3>Example 2: Header Navigation</h3>
<strong>File:</strong> header.php (in your theme)
<pre><code class="language-php">
<nav class="main-navigation">
<ul class="menu">
<ul>
<li><a href="/%3C?php%20echo%20home_url(%27/%27);%20?%3E">Home</a></li></ul>
<ul>
<li><a href="/%3C?php%20echo%20home_url(%27/about/%27);%20?%3E">About</a></li></ul>
<ul>
<li><a href="/%3C?php%20echo%20home_url(%27/contact/%27);%20?%3E">Contact</a></li></ul>
<?php if (!is_user_logged_in()) : ?>
<li class="menu-login-button">
<a href="/" id="header-login-toggle">Login</a>
</li>
<?php else : ?>
<li class="menu-user-info">
<a href="/%3C?php%20echo%20home_url(%27/dashboard/%27);%20?%3E">
<?php echo wp_get_current_user()->display_name; ?>
</a>
</li>
<li class="menu-logout">
<a href="/%3C?php%20echo%20wp_logout_url(home_url());%20?%3E">Logout</a>
</li>
<?php endif; ?>
</ul>
</nav>
<?php if (!is_user_logged_in()) : ?>
<div id="header-login-dropdown" style="display:none;">
<?php attributes_login_form(array(
'redirect' => home_url('/dashboard/'),
'form_id' => 'header_login'
));
?>
</div>
<?php endif; ?>
Add JavaScript to toggle dropdown:
<script>
jQuery(document).ready(function($) {
$('#header-login-toggle').click(function(e) {
e.preventDefault();
$('#header-login-dropdown').slideToggle();
});
});
</script>
Example 3: Sidebar Widget Area
File: sidebar.php or widget area
<pre><code class="language-php">
<?php if (!is_user_logged_in()) : ?>
<div class="widget login-widget">
<h3 class="widget-title">Member Login</h3>
<?php attributes_login_form(array(
'redirect' => home_url('/member-area/'),
'form_id' => 'sidebar_login',
'label_username' => 'Email',
'label_password' => 'Password',
'label_submit' => 'Login'
));
?>
</div>
<?php else : ?>
<div class="widget user-info-widget">
<h3 class="widget-title">Welcome Back</h3>
Hello, <?php echo wp_get_current_user()->display_name; ?>!
<a href="/%3C?php%20echo%20home_url(%27/dashboard/%27);%20?%3E">My Dashboard</a>
<a href="/%3C?php%20echo%20wp_logout_url(home_url());%20?%3E">Logout</a>
</div>
<?php endif; ?>
Example 4: Popup Modal Login
File: footer.php (in your theme)
<pre><code class="language-php">
<!-- Login Modal -->
<div id="login-modal" class="modal" style="display:none;">
<div class="modal-overlay"></div>
<div class="modal-content">
<span class="modal-close">×</span>
<h2>Login to Your Account</h2>
<?php attributes_login_form(array(
'redirect' => home_url('/dashboard/'),
'form_id' => 'modal_login'
));
?>
</div>
</div>
<script>
jQuery(document).ready(function($) {
// Open modal
$('.open-login-modal').click(function(e) {
e.preventDefault();
$('#login-modal').fadeIn();
});
// Close modal
$('.modal-close, .modal-overlay').click(function() {
$('#login-modal').fadeOut();
});
});
</script>
Add trigger button anywhere:
<a href="/" class="open-login-modal">Login</a>
Example 5: Footer Quick Login
File: footer.php
<pre><code class="language-php">
<footer class="site-footer">
<div class="footer-content">
<div class="footer-left">
© <?php echo date('Y'); ?> <?php bloginfo('name'); ?>
</div>
<?php if (!is_user_logged_in()) : ?>
<div class="footer-login">
<h4>Quick Login</h4>
<?php <p> attributes_login_form(array(
'redirect' => home_url('/dashboard/'),
'form_id' => 'footer_login',
'label_submit' => 'Go'
));
?>
</div>
<?php endif; ?>
<div class="footer-right">
<nav class="footer-menu">
<?php wp_nav_menu(array('theme_location' => 'footer')); ?>
</nav>
</div>
</div>
</footer>
Conditional Display Logic
Show Form to Logged-Out Users Only
<?php if (!is_user_logged_in()) : ?>
<?php attributes_login_form(); ?>
<?php else : ?>
You are already logged in! <a href="/%3C?php%20echo%20home_url(%27/dashboard/%27);%20?%3E">Go to Dashboard</a>
<?php endif; ?>
Show Different Forms Based on Role
<?php if (!is_user_logged_in()) {
// Show login form
attributes_login_form();
} elseif (current_user_can('manage_options')) {
// Administrator
echo 'Welcome Admin! <a href="/wp-admin/">Admin Dashboard';
} elseif (current_user_can('edit_posts')) {
// Editor or Author
echo 'Welcome! <a href="/wp-admin/edit.php">Manage Posts</a>';
} else {
// Subscriber
echo 'Welcome! <a href="/member-dashboard/">Member Dashboard</a>';
}
?>
Show Form on Specific Pages Only
<?php if (is_page('restricted-content')) : ?>
<?php if (!is_user_logged_in()) : ?>
<div class="login-required">
<h3>Login Required</h3>
Please login to view this content.
<?php attributes_login_form(array('redirect' => get_permalink())); ?>
</div>
<?php endif; ?>
<?php endif; ?>
WordPress Functions to Use With Forms
Useful User Functions
Check if user is logged in:
<?php if (is_user_logged_in()) { } ?>
Get current user info:
<?php $current_user = wp_get_current_user();
echo $current_user->display_name; // User's display name
echo $current_user->user_email; // User's email
?>
Check user capabilities:
<?php if (current_user_can('manage_options')) {
// User is administrator
}
?>
Logout URL:
<?php echo wp_logout_url(home_url()); ?>
Profile edit URL:
<?php echo admin_url('profile.php'); ?>
Styling Embedded Forms
Add Custom CSS
Target forms by ID:
/<em> Header login form </em>/
#header_login.attributes-login-form {
padding: 10px;
background: #f0f0f0;
}
/<em> Sidebar login form </em>/
#sidebar_login.attributes-login-form {
font-size: 14px;
}
/<em> Footer login form </em>/
#footer_login.attributes-login-form {
display: flex;
gap: 10px;
align-items: flex-end;
}
#footer_login.attributes-login-form input[type="text"],
#footer_login.attributes-login-form input[type="password"] {
flex: 1;
}
Best Practices
- Use child themes: Preserve changes during theme updates
- Unique form IDs: Different ID for each embedded form
- Test thoroughly: Verify all forms work correctly
- Mobile responsive: Ensure forms work on small screens
- Security: Never expose sensitive information in templates
- Error handling: Display helpful error messages
Troubleshooting
Function Not Found Error
Error:
Solutions:
Safe implementation:
Fatal error: Call to undefined function attributes_login_form()Solutions:
- Verify plugin is installed and activated
- Check plugin version (function available in v1.0+)
- Wrap function in
function_exists()check
<?php if (function_exists('attributes_login_form')) {
attributes_login_form();
} else {
echo 'Login form not available. Please install Attributes User Access.';
}
?>
Form Not Displaying
Solutions:
- Check PHP syntax for errors
- Verify template file location
- Clear all caching
- Check if conditional logic is hiding form
CSS Conflicts
Solutions:
- Use more specific CSS selectors
- Target form by unique ID
- Check theme’s CSS for conflicts
- Use
!importantas last resort
Pro Tips
Always Use Child Themes
Edit theme files only in child themes to prevent loss of changes during theme updates.
Cache Considerations
Embedded forms in headers/footers may be cached. Configure caching plugins to exclude login forms.
AJAX Forms
Consider enabling AJAX login (Pro feature) for embedded forms to prevent page reloads.