How to implement inline cm/inches conversion in WordPress

One way is to create a shortcode for it

add_shortcode( 'cm2inches', function( $atts, $content ) {
     return $content*0.393701;
}

Can be used like this

The length of a European ruler is often [cm2inches]30[/cm2inches] inches.

But remember, when you display content it doesn’t automatically get parsed through do_shortcode. Let’s say you’ve saved some meta box information as a site option. Then do it like this:

echo do_shortcode( get_option( 'option_name' ) );

Leave a Comment