• Here is an image of my comment format: https://oi40.tinypic.com/8w07jt.jpg

    The hyperlink to each individual comment is the date and time with the url in the format of, for example: /nottingham/#comment-184 – FYI I’m using the Photoria theme.

    After going through my comment templates I found that these two functions do the following,

    get_comments_link : Retrieves the link to the current post comments

    AND

    comments_link: Displays the link to the current post comments

    The problem is I have no idea where to include these functions so it creates a hyperlink to every comment within every comment. Once this link has been created I’d also like to assign a div to it so I can format it to be in the bottom right corner of each comment. On another forum one person replied to me “you need to locate the template for 1 comment in your loop and post it in your question” but I’m not sure how to do this! I removed the comments function from my loop because I wanted the comments to display on all pages only, so put it in page.php instead. So not sure whether he meant that code or the code from comments.php (wp_list_comments) ?

    My final goal is to manipulate the link so rather than the comment link itself it will automatically work in the facebook.com/sharer.php which I feel I can do myself once I figure out the previous part. Essentially it will be a share on facebook button, but I have found no plugins which do this yet and thought describing it as a hyperlink would be an easier way to explain what I’m trying to do.

    I hope I’ve made the question clear, please ask if I haven’t. Thanks in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • If I wanted to do that I’d use a child theme to avoid messing with the main theme, and to allow the main theme to update without overwriting changes. If you’ve already modified the main theme a lot, maybe it’s too late to back out.

    In functions.php I’d add a ‘get_comments_link‘ filter to return the desired link, including the <div> tag you need. Note that this is a filter, not a function. There is function with the same name, but it’s part of WordPress itself.

    Thread Starter PauloCot

    (@paulocot)

    Thanks Rod, I’ll keep that in mind and make sure to backup before doing any updates.

    Which functions.php because there is one within the theme and others within the WordPress directory. Also, I want to add another link not edit the old one.

    I guess my main problem is I don’t know how or where to edit the code so it applies to all comments.

    I’m sorry. I misunderstood your original question. However, I think what I suggested might still work.

    If you have already gone down the route of editing the theme, then edit functions.php in the theme. Your edits will be lost if you ever update the theme. Otherwise create a child theme and make a new functions.php there. Don’t edit any WordPress files, because your edits will be lost if you ever update WordPress.

    Use the filter to add a <div> to the existing link. Then style the new <div> to position it where you want it. I notice that the Photoria theme repositions the Reply link, which is coded at the bottom but displayed at the top. In the same way, your new <div> will be coded at the top but displayed at the bottom.

    Thread Starter PauloCot

    (@paulocot)

    My functions.php looks like this:

    <?php
    /**
     * WPZOOM Theme Functions
     *
     * Don't edit this file until you know what you're doing. If you mind to add
     * functions and other hacks please use functions/user/ folder instead and
     * functions/user/functions.php file, those files are intend for that and
     * will never be overwritten in case of a framework update.
     */
    
    /**
     * Paths to WPZOOM Theme Functions
     */
    define("FUNC_INC", get_template_directory() . "/functions");
    
    define("WPZOOM_INC", FUNC_INC . "/wpzoom");
    define("THEME_INC", FUNC_INC . "/theme");
    define("USER_INC", FUNC_INC . "/user");
    
    /** WPZOOM Framework Core */
    require_once WPZOOM_INC . "/init.php";
    
    /** WPZOOM Theme */
    require_once THEME_INC . "/functions.php";
    require_once THEME_INC . "/sidebar.php";
    require_once THEME_INC . "/post-options.php";
    
    /* Theme widgets */
    require_once THEME_INC . "/widgets/featuredposts.php";
    require_once THEME_INC . "/widgets/flickrwidget.php";
    require_once THEME_INC . "/widgets/social.php";
    
    /** User functions */
    require_once USER_INC . "/functions.php";

    Should I do the changes in the functions file it suggests.

    I’m not quite sure what you mean by filter and how the code would look. Would it be a case of adding:

    add_filter( 'get_comments_link', 'filter_function_name', 10 );
    
    function filter_function_name( $link) {
        // Manipulate comment link
        return $link;
    }

    To the functions.php file and adding a div to it or is there more coding required? Also what does the 10 in the code stand for?

    Be patient with me! ??

    Yes, try following the instructions. Also see add_filter in the Codex. Add the new <div> to $link before returning it. The new <div> will need a class attribute so that you can work with it in CSS to make it look the way you want.

    I have never used the Photoria theme, and I have never attempted what you are attempting, so I cannot provide details of the coding that will be needed.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding a hyperlink to every comment’ is closed to new replies.