0

OK, I have a working line of code that acts nearly as I want it to, but instead of creating a shortcode in WordPress, it just spits out the text. I need the outputted text to be a shortcode. I've tried everything I know of, but to no avail.

Can someone alter this code so that it outputs the text (beginning with [imdb]http://... as a shortcode?

<?php
global $wp_query;
$postid = $wp_query->post->ID;
if( get_post_meta($postid, 'imdb', true)) { ?>
<h3>IMDb Information</h3>
[imdb]http://www.imdb.com/title/<?php echo get_post_meta($postid, 'imdb', true);
?>/[/imdb]
<?php } 
       elseif( get_post_meta($postid, 'ecpt_imdb', true)) { 
?>
<h3>IMDb Information</h3>
[imdb]http://www.imdb.com/title/<?php echo get_post_meta($postid, 'ecpt_imdb',    true);
?>/[/imdb]
<?php } ?>
2
  • what do you mean for short code ? a link? an ancor?
    – ScaisEdge
    Sep 28, 2015 at 16:51
  • Basically this code works, but it spits out this: [imdb]imdb.com/title/imdb_of_movie/[/imdb] I want to have that line of text above be a shortcode instead of plain text. In essence, I can't get it to work with the do_shortcode function.
    – user34872
    Sep 28, 2015 at 16:52

1 Answer 1

0

Maybe I am not getting your code, and in that case sorry. But if the idea is that it should print out the result of the [imdb] shortcode, which I imagine would create some kind of information taken from IMDB, probably what you want is something close to:

<h3>IMDb Information</h3>
<?= do_shortcode("[imdb]http://www.imdb.com/title/" . get_post_meta($postid, 'imdb', true) . "[/imdb]") ?>
0

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.