• Resolved HorrorUK

    (@horroruk)


    I’m trying to show a different image, with a link, depending on whether a user is logged in or not.

    What I’d like to do would be something like this:

    <?php
    if ( is_user_logged_in() ) {
        <A HREF="/"><IMG SRC="<?php bloginfo('template_directory'); ?>/images/createblog.jpg" border="0"></A>
    
    } else {
    <A HREF="/"><IMG SRC="<?php bloginfo('template_directory'); ?>/images/createblogloggedout.jpg" border="0"></A>
    
    };
    ?>

    However, as it doesn’t allow commands within the statement, I can’t figure out how to do it.

    How would I show an image within that structure?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • you need to close the php tags before the html code and then open new php tags for more php code:
    principle:
    <?php PHP-CODE ?> HTML-CODE <?php PHP-CODE ?>
    even in an if statement.

    <?php
    if ( is_user_logged_in() ) { ?>
        <a href="/"><img src="<?php bloginfo('template_directory'); ?>/images/createblog.jpg" border="0"></a>
    
    <?php } else { ?>
    <a href="/"><img src="<?php bloginfo('template_directory'); ?>/images/createblogloggedout.jpg" border="0"></a>
    
    <?php };
    ?>
    Thread Starter HorrorUK

    (@horroruk)

    Thanks, works perfectly now ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘use an href within an if/else statement’ is closed to new replies.