I would like to change the text on “post comment” button?


#1

Hi,

We have just installed your sydney theme. First impressions are great and we will be looking at going live to the pro version after we have confirmed a few questions.

Our test server is alpha2.sports-future.co.uk

The first question is obviously in the topic title. Our website would like a particular blog category to have different text on the ‘Post Comment’ button, is this possible? All other categories should still have the default ‘Post Comment’ text.

I will keep it at one question per topic to avoid brain overload and maybe make it simpler for others who would like the same customization in the future.

Many thanks in advance.

Martin


#2

Hello there,

Thank you for asking.

I thought it is possible to achieve. Could you please try to add the following snippet to the child theme’s functions.php file?

add_filter('comment_form_defaults', 'sydney_child_custom_submit_comment_label');
function sydney_child_custom_submit_comment_label($defaults){

  global $post;

  $post_categories = wp_get_post_terms( $post->ID, 'category' );

  $cat_slugs = array();
  foreach ($post_categories as $post_cat) {
    $cat_slugs[] = $post_cat->slug;
  }

  // Global text label
  $defaults['label_submit'] = __('Post Comment', 'sydney');

  // Text label for particular category slug(s)
  $selected_cats = array('lectures');
  if(array_intersect($cat_slugs, $selected_cats)) {

    $defaults['label_submit'] = __('Submit Comment', 'sydney');

  }

  return $defaults;

}

The “Submit Comment” string will be applied only for the lectures category slug only. If you want it be applied to another category as well, try to change the $selected_cats = array(‘lectures’); line into the following:

$selected_cats = array('lectures', 'my-other-cat-slug');

The value must be the category slug.

If you haven’t installed and activated the child theme, you could download it here.

Let me know how it goes.

Regards,
Kharis


#3

Thanks Kharis, I will implement this and get back to you.

Kind regards,

Martin


#4

Thanks Kharis, it works perfectly!

Kind regards,

Martin


#5

Nice!

You’re welcome!

Please let us know in a new topic if you have any further questions, or if we can provide you with any other assistance.

If you don’t mind, could you please rate our Sydney theme here? We would highly appreciate it if you do so.

Regards,
Kharis