Archive for the ‘wordpress’ Category

How to change comment reply link text in wordpress?

I had to do that and had spent some time till I found/figured out how to do it without modifying wordpress core files. There are some information on the internet, but I think I will write it in the way it is more understandable for me, maybe for someone it will be usefull as well.

I was using theme which had a file comments.php in its root directory. So I guess the good chance is that your theme also will have this.

In comments.php there is a function

wp_list_comments('avatar_size=70&callback=custom_comment&type=comment');

of course parameters could be different or the function can be even without them. As you can see there is one parameter called ‘callback’. This is the function which overrides the appearance of comment. In our case the function is named ‘custom_comment’ but you can use your own name.

Now we must have that function, or it could have came already with a theme. In my case it came with a theme and it was placed in themes directory includes/theme_comments.php. Probably in another theme this might be something similar. It looked something like this (now its modified by me):

// Fist full of comments
function custom_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
 
	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
 
    	<a name="comment-<?php comment_ID() ?>"></a>
 
      	<div class="comment-container">
 
			<?php if(get_comment_type() == "comment"){ ?>
 
            <div class="avatar"><?php the_commenter_avatar($args) ?></div>
 
            <?php } ?>
 
            <div class="comment-right">
 
                <div class="comment-head">
 
                    <span class="name fl"><?php the_commenter_link() ?></span>
 
                    <?php if(get_comment_type() == "comment"){ ?>
 
                        <span class="reply fr"><?php comment_reply_link(array_merge( $args, array('reply_text' => 'Atsakyti' ,'depth' => $depth, 'max_depth' => $args['max_depth']))) ?></span><!-- /.reply -->
                        <span class="date fr"><a href="<?php echo get_comment_link(); ?>" title="<?php _e('Direct link to this comment', 'woothemes'); ?>"><?php echo get_comment_date(get_option('date_format')) ?> <?php _e('at', 'woothemes'); ?> <?php echo get_comment_time(); ?></a></span>
                    <?php }?>
                        <span class="edit fr"><?php edit_comment_link('Edit &nbsp;', '', ''); ?></span>
 
                </div><!-- /.comment-head -->
 
                <div class="comment-entry"  id="comment-<?php comment_ID(); ?>">
 
                    <?php comment_text() ?>
 
                    <?php if ($comment->comment_approved == '0') { ?>
                        <p class='unapproved'><?php _e('Your comment is awaiting moderation.', 'woothemes'); ?></p>
                    <?php } ?>
 
 
                </div><!-- /comment-entry -->
 
            </div><!-- /comment-right -->
 
		</div><!-- /.comment-container -->
 
 
<?php
}

There is a called function comment_reply_link() – as you can see in the array there is item ‘reply_text’ with a value. So change that value by your needs and thats it :)

You also might not see that item, because it is optional, in my case I had to add it myself too. If you want to see all the posible parameters, you can go to wordpress core files – directory includes/comment-template.php and look at the function

get_comment_reply_link()

there is an array $defaults and there are all posible variables, in case you don’t like default values.

Also there is one another, more simple thing, but I will still tell it – you might want to change the text of cancel comment reply link.
So if you want to do that – open comments.php in your theme directory and find a function

cancel_comment_reply_link

and its parameter is string (optional). So if you put some string, it will replace the default text. (It probably is a chance that there is no such function in your theme, but I am not sure, because I myself still haven’t worked too much with wordpress).

How to make “Home” link visible on all pages except the front page in wordpress

Once I needed to do this, but could not find how to do it without editing a code. So by some similar examples I made this code.

Place this in your themes directory, functions.php:

add_filter('wp_get_nav_menu_items', 'removeHome');
function removeHome($menu) 
{
	$homeUrl = get_bloginfo('url') . '/';
	if (is_home()) {	
		foreach ($menu as $key => &$m) {
 
			if ($m->url == $homeUrl) {
				unset($menu[$key]);
				break;
			}
		}
	}
	return $menu;
}

Here we assume that home link has ‘/’ at the end. But if you want that it would not care if its ‘/’ at the end or not, I think it will not hard to modify it. As you can see this script loops through menu items and unsets the array element which has the url as it is our home url.

Nothing fancy in the script itself, but for a some the biggest problem could be to find what to modify, how to get that menu array, what filter to use. It took time for me at least.