WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Request URI (5 posts)

  1. caylean
    Member
    Posted 1 year ago #

    I was thinking this would be an easy Task, i still believe it is, but without PHP knowledge it is impossible to do correctly.

    I try to add to an Link the active uri.

    <a onclick="popUpWin(this.href, 'console', 660, 425, 50, 50);return false;" href="http://www.facebook.com/sharer.php?u=<?php echo $_SERVER['REQUEST_URI']; ?>"><img src="<?php bloginfo('url'); ?>/images/facebook.png" alt="Facebook" width="20" height="20" border="0" /></a>

    If a user is on the main site he has the correct url in the Link, if he is in a posting he also has it.

    But whatever i Try like this Actual Code i posted above, or this

    <?php
    if (is_home())
    echo "<?php bloginfo('url'); ?>";
    }
    else {
    echo "<?php the_permalink() ?>";
    }
    ?>

    instead of <?php echo $_SERVER['REQUEST_URI']; ?> --- it all isn't function, could someone tell me where i do wrong? and how I could fix that, without using any kind of Plugin?

    Kind Regards

  2. s_ha_dum
    Member
    Posted 1 year ago #

    This...

    if (is_home())
    echo "<?php bloginfo('url'); ?>";
    }

    ... will echo the literal string "<?php bloginfo('url'); ?>". You don't need to quote your argument and add a PHP block. You are already 'in' PHP. You are also missing a '{'. That should be...

    if (is_home()) {
    echo bloginfo('url');
    }
  3. caylean
    Member
    Posted 1 year ago #

    THanks, thats it! :)

    <?php if (is_home()) { echo bloginfo('url'); } else { echo the_permalink(); } ?>

    and it is all fine. This missing { comes due to the fact i know nothing about php :)

    Just for some cosmetics in the echo bloginfo('url') -- Is it possible to add an / in the end to the Link? Now it is just http://test.domain.tld

    But all in all it is resolved, thanks.

  4. s_ha_dum
    Member
    Posted 1 year ago #

    Yes, just tack it on bloginfo('url').'/';

  5. caylean
    Member
    Posted 1 year ago #

    Hehe, thats indeed very easy, if you know that there yould be .' before and a ' behind it *g*
    Without it, you generate again just crap ;)

    Thanks s_ha_dum for your kindness and fast help!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.