How to implement inline cm/inches conversion in WordPress

I am having trouble implementing inline cm/inch conversion inside WordPress.

I was using plugin called “Unit Converter” http://wordpress.org/extend/plugins/unit-converter/ and it worked fine when I adjusted it to work with custom meta boxes. It showed inline conversion from cm to inches.

Read More

Now I created custom search so I no longer can add “cm” at the end of each number and converter no longer works.

 Height: <?php echo rwmb_meta( 'iz_height' ); ?> cm</li> 

Since size value now comes from custom meta boxes but “cm” sign from theme this plugin I mentioned no longer works.

How to make this plugin work or how I can convert these units without using plugins.
Basically I am looking for solution to convert “RandomNumber cm” to inches.

Related posts

Leave a Reply

1 comment

  1. 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' ) );