WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding HTTP:// To Comment URIs (5 posts)

  1. tsguitar
    Member
    Posted 8 years ago #

    If a visitor comes to my site, leaves a comment, but doesn't type http:// before his address in the URI box, when I view that person's comment, the link to their site is broken. WordPress doesn't add http:// to their link if it isn't there and without it their link won't work.

    Am I missing something that I can to turn on? Is there a convenient way to add that? I don't mind editing WP files, but if there's a plugin for this, I appreciate the tip. Thank you.

  2. Cypher
    Member
    Posted 8 years ago #

    There is no setting for it. You'll probably have to alter the comments.php file for your theme to check for the "http://" portion in the URI and add it if it's not there.

    Regards

  3. tsguitar
    Member
    Posted 8 years ago #

    Any ideas about how I'd do that? Using comment_author_link(), which is both the URL and the commenter's name, doesn't really allow me to do much with it.

    I tried:
    $url = str_replace("http://","",comment_author_link());
    // take it out if it is there
    $url1 = str_replace("www","http://www", $url);
    // since none of them have it, add it in to every one
    echo $url1;

    That didn't work. Any other ideas about how to check for the http:// and add it if it's not there?

  4. Kafkaesqui

    Posted 8 years ago #

    Try replacing comment_author_link() with this:

    <?php
    echo preg_replace('%href=([\"|\'])(?!http://)%i', "href=$1http://", get_comment_author_link());
    ?>

    The regular expression used above in preg_replace() matches an href value *not* beginning http:// and inserts that into the output.

  5. tsguitar
    Member
    Posted 8 years ago #

    That does it. Nice job, as always, Kafkaesqui. It works perfectly. Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.