Reformatting output of the [rank_math_contact_info] shortcode

  • Hello. I’d like to edit the output of the [rank_math_contact_info] shortcode. For example, I’d like to insert line breaks within the address. Where does this information reside?

    Also, if it’s possible, I’d also like to remove the map and create another version of the shortcode to display *only* the map. Is this possible?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello,

    Thank you for contacting Rank Math today.

    I am consulting our dev team about this and I will be in touch after a short while.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    Please use below filter code to add line breaks within the address:

    
    add_filter( 'rank_math/shortcode/contact/address_parts_format', function( $parts ){
        return $parts . '<br />';
    });
    
    

    Also, if it’s possible, I’d also like to remove the map and create another version of the shortcode to display *only* the map. Is this possible?

    To remove the map from the existing shortcode and display it in a new shortcode, please add below code in functions.php file:

    
    add_filter( 'shortcode_atts_contact-info', function( $out, $pairs, $atts, $shortcode ){
    	$out['show'] = 'address, hours, phone, social';
    	return $out;
    }, 10, 4 );
    
    add_shortcode( 'rank_math_contact_info_map', function(){
    	$address = RankMath\Helper::get_settings( 'titles.local_address' );
    	if ( false === $address ) {
    		return;
    	}
    
    	/**
    	 * Filter address for Google Map in contact shortcode.
    	 *
    	 * @param string $address
    	 */
    	$address = apply_filters( 'rank_math/shortcode/contact/map_address', implode( ' ', $address ) );
    	$address = apply_filters( 'rank_math/shortcode/contact/map_iframe_src', '//maps.google.com/maps?q=' . urlencode( $address ) . '&z=15&output=embed&key=' . urlencode( RankMath\Helper::get_settings( 'titles.maps_api_key' ) ) );
    
    	return '<div class="rank-math-contact-section rank-math-contact-map"><iframe src="' . esc_url( $address ) . '"></iframe></div>';
    });
    

    After adding this code, you can use [rank_math_contact_info_map] shortcode to show the map.

    I hope that helps. If there is anything else, please let us know.

    Thank you.

    Excellent! Thanks!

    I’m becoming more enthused with RankMath as I continue to work with it. FWIW, I think that the more that these sorts of functions are exposed and documented (or perhaps baked into the plugin itself) the greater the adoption and success there will be.

    Cheers!

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/?rate=5#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘Reformatting output of the [rank_math_contact_info] shortcode’ is closed to new replies.