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

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’.

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.