How to change the “View Listing” text – AgentPress Listings Plugin

Alter View Listing Text
Alter View Listing Text

Lot of users are asking this question: How to modify the “View Listing” text?. Very simple way you can change the text. Just drop the following code in your functions.php file and see the magic.

add_filter( 'gettext', 'agentpress_change_view_listings_text', 20, 3 );
/**
 * Change view listings text.
 *
 * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
 * @see switch http://php.net/manual/en/control-structures.switch.php
 */
function agentpress_change_view_listings_text( $translated_text, $text, $domain ) {

    if ( ( 'agentpress-listings' == $domain ) || ( 'agentpress' == $domain ) ) {

        switch ( $translated_text ) {

            case 'View Listing' :

                $translated_text = __( 'Modified Text', 'agentpress-listings' );
                break;
                
        }

    }

    return $translated_text;
}

“View Listing” text is replacing with “Modified Text”.

Explain: Code is using the WordPress’s gettext() filter. This filter hook is applied to the translated text by the internationalization functions (__(), _e(), etc.). Filter function is accepting three arguments: ‘translated text’, ‘untranslated text’ and ‘text domain’.

IMPORTANT: This filter hook is always applied even if internationalization is not in effect, and if the text domain has not been loaded.

Above code will only work if load text domain is ‘agentpress-listings’ or ‘agentpress’.

Share This Article

Subscribe Membership Plan ($9.99/mo)

  • Get full access to all premium tutorials
  • Get Support for the posted content
  • Request for specific how-to tutorials
  • Cancel the subscription at anytime

Reader Interactions

2 Discussion to This Post

Leave A Reply

Your email address will not be published. Required fields are marked *