Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8366499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:56:06+00:00 2026-06-09T12:56:06+00:00

I have a PHP file in WordPress that has some HTML, Login & Register

  • 0

I have a PHP file in WordPress that has some HTML, “Login & Register” that I would only like to show when a member of the site is not logged in. When they are logged in I would like it to show “Welcome, [name].”

I’m just not sure how to use HTML in a PHP If statement. The condition is this:

<?php
      if ( member_is_logged_in() ) {
         print "Welcome [name]";
      } else {
         print "<a href="...">Login</a> | <a href="...">Register</a>";
      }
?>

That’s how I think it should look, but it’s not working. I’m not that great with PHP, but I would appreciate any help. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:56:08+00:00Added an answer on June 9, 2026 at 12:56 pm

    You can use PHP variables in double quoted strings. so just replace [name] with $name or whatever the variable is. Note this will not work with single quotes.

    Also, you have two sets of double quotes in the else case. This will result in a syntax error. Make one of them single quotes or escape the inside quotes.

    <?php
          if ( member_is_logged_in() ) {
             print "Welcome $name";
          } else {
             print '<a href="...">Login</a> | <a href="...">Register</a>';
          }
    ?>
    

    You can also just end the PHP tag and write the HTML directly.

    <?php
          if ( member_is_logged_in() ) {
             print "Welcome $name";
          } else {
    ?>
             <a href="...">Login</a> | <a href="...">Register</a>
    <?php
          }
    ?>
    

    There exists a better and easier to read syntax for this:

    <?php if(<your evaluation here>): ?>
    HTML for when true
    <?php else: ?>
    HTML for when false
    <?php endif; ?>
    

    Check out Alternative syntax for control structures for more information on this.

    And while we’re at it, print vs echo, which one is faster?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file which has some variables like $name1, $name2... How can
I have an ajax.php file in my Wordpress themes folder, and this was working
In wordpress, I have the loop.php file. There I can see the 'read more'
I have a PHP File with something like this: <script type=text/javascript> var page =
I have a PHP file that contains a large array (about 90KB). I'm considering
I have a php file which checks for login and password from users database,
I have a function in a functions.php file that defines certain variables: add_action( 'the_post',
We all know that wordpress have simple .htaccess code like below RewriteEngine on RewriteBase
I have SQL queries that I want to run automatically after wordpress installation has
I have installed wordpress in root directory. There is a file say test.html in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.