Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Shortcode & PHP WordPress

  • SOLVED

Hello I am trying to show a custom field 'twitter-user' within a shortcode that is used within the theme of my site. Can someone help me with the correct code, I realise that the below won't work.

<?php echo do_shortcode('[twitter-widget username="<?php echo get_post_meta( get_the_ID(), 'twitter-user', true ); ?>"]'); ?>

Thank you

Answers (4)

2013-12-09

Francisco Javier Carazo Gil answers:

<?php echo do_shortcode('[twitter-widget username="<?php echo get_post_meta( get_the_ID(), 'twitter-user', true ); ?>"]'); ?>

Is bad formed, try with:
<?php echo do_shortcode('[twitter-widget username="' . get_post_meta( get_the_ID(), 'twitter-user', true ) . '"]'); ?>

2013-12-09

Arnav Joy answers:

try this

<?php echo do_shortcode('[twitter-widget username="'.get_post_meta( get_the_ID(), 'twitter-user', true ).'"]'); ?>

2013-12-09

Hariprasad Vijayan answers:

Hello,

Try this

<?php echo do_shortcode('[twitter-widget username="'.get_post_meta( get_the_ID(), 'twitter-user', true ).'"]'); ?>

2013-12-09

Fahad Murtaza answers:

<?php

$twitter_id=get_post_meta( get_the_ID(), 'twitter-user', true );

echo do_shortcode('[twitter-widget username="'.$twitter_id.'"]');
?>


Fahad Murtaza comments:

wow, 4 responses as I just typed my solution :) wpquestions is amazing :)