Skip to:
Content
Pages
Categories
Search
Top
Bottom

Replace topic subscription text


  • vincenzon617
    Participant

    @vincenzon617

    Hi,

    is there a way to change the text of the subscription button? Currently it says ‘Subscribe’ and ‘Unsubscribe’ and I would like to change to ‘Watch’ and ‘Unwatch’ respectively. I believe the code that can change this is within the file \bbpress\includes\topics\template.php lines 1781 and 1782. I could change them in here but I would rather change them via my child theme if this is possible?

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

  • Robin W
    Moderator

    @robin-w

    untested, but this should work

    add_filter ('bbp_before_get_topic_subscribe_link_parse_args' , 'change_subscribe') ;
    
    function change_subscribe ($args) {
    	$args['subscribe'] = 'Watch' ;
    	$args['unsubscribe'] = 'Unwatch' ;
    return $args ;
    }

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets


    vincenzon617
    Participant

    @vincenzon617

    Thanks, the code works however only when loading onto the page. When I click to either ‘Watch’ or ‘Unwatch’ the text reverts back to ‘Unsubscribe’ or ‘Subscribe’ until I refresh the page again.


    Robin W
    Moderator

    @robin-w

    ok, try this

    add_filter( 'gettext', 'rew_change_text', 20, 3 );
    
    //This function changes the text wherever it is quoted
    function rew_change_text( $translated_text, $text, $domain ) {
    	if ( $text == 'Subscribe' ) {
    	$translated_text = 'Watch';
    	}
    	if ( $text == 'Unsubscribe' ) {
    	$translated_text = 'Unwatch';
    	}
    	return $translated_text;
    }

    vincenzon617
    Participant

    @vincenzon617

    Works perfectly, thanks!


    Robin W
    Moderator

    @robin-w

    great – glad you are fixed !!


    Robin W
    Moderator

    @robin-w

    The way subscriptions works has changed

    use this code now :

    add_filter ('bbp_before_get_user_subscribe_link_parse_args' , 'change_subscribe') ;
    
    function change_subscribe ($args) {
    	$post_id = $args['object_id']  ;
    	if (bbp_is_topic( $post_id )) $text = 'topic' ;
    	if (bbp_is_forum( $post_id )) $text = 'forum' ;
    	$args['subscribe'] = 'Subscribe to this '.$text ;
    	$args['unsubscribe'] = 'Unsubscribe' ;
    return $args ;
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar