I have a custom theme that a third party developed for me and I’m trying to get to the bottom of a problem with shortcodes. I’m fairly new to Wordpress and PHP so please let me know if there is any other information I can supply.

I have custom text fields where I enter product prices. I am using the Custom Content By Country plugin so that I can display region-specific prices in these fields. This plugin uses a shortcode to specify what prices should be displayed for each country. For example:

[CBC country="gb" show="y"]£10[/CBC][CBC country=“us” show=“y”]$15[/CBC]

I worked out how to use the do_shortcode function in my template to actually get the shortcode to work, like this:

<?php echo do_shortcode( get_post_meta($post->ID, 'fl_prodbuy1price', true) );?>

This works fine the first time I publish the post. My problem is that, once I click Publish/Update in the Wordpress UI, Wordpress truncates the displayed contents of the field - always at the first equals (=) sign:

[CBC country=

So if I go back and edit the post and update it, unless I remember to re-enter the full shortcode it publishes the post with a value of [CBC country= for the price.

Does this problem ring any bells for anyone? I’d appreciate any suggestions on where I should focus investigation.

  • 1
    it's probably incorrect handling of quotes somewhere.
    – Milo
    Jan 19, 2016 at 19:39
  • @Milo is right, maybe run it through esc_attr()
    – Howdy_McGee
    Jan 19, 2016 at 19:39
  • Thanks - I'll give that a go and see what I can find out.
    – Jo G
    Jan 19, 2016 at 21:29

1 Answer 1


@Milo and @Howdy_McGee had the answer.

I found the section I needed to modify in my functions.php file:

case 'text':
echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" 
value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />',

It was the value field that was getting truncated, so I passed it through esc_attr() as suggested:

case 'text':
echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" 
value="', esc_attr($meta ? $meta : $field['std']), '" size="30"   style="width:97%" />',

Problem solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.