Skip to content

PHP Customization - how to limit property card address length (e.g. max 9 words)?

1 minute read

  1. 1 Find plugins/myhome-core/includes/estates/Estate.php
  2. 2 Backup the file
  3. 3 Find get_name function
php
public function get_address() {
   if ( ! empty( \MyHomeCore\My_Home_Core()->settings->props['mh-estate_hide-address'] ) ) {
      return '';
   }

   $location = $this->get_location();

   return empty( $location['address'] ) ? '' : $location['address'];
}

4. Change it (9 is a limit of a words)

php
public function get_address() {
   if ( ! empty( \MyHomeCore\My_Home_Core()->settings->props['mh-estate_hide-address'] ) ) {
      return '';
   }

   $location = $this->get_location();

       $text = $location['address'];
       $limit = 9;

       if (str_word_count($text, 0) > $limit) {
           $words = str_word_count($text, 2);
           $pos = array_keys($words);
           $text = substr($text, 0, $pos[$limit]) . '...';
       }
       return $text;

}

Ask the people who build MyHome WPBakery

We answer by email from support@tangiblewp.com. With Premium Support, we also fix your site when something breaks.

Was this guide helpful?