Please help me execute a shortcode outside the POST CONTENT in a theme. I have created a plugin as following:
<?php
add_shortcode('jplayer', 'embed_player');
if (!is_admin()) {
add_filter('widget_text', 'do_shortcode');
}
add_filter('the_excerpt', 'do_shortcode', 11);
add_filter('the_content', 'do_shortcode', 11);
function embed_player($atts, $content = null) {
extract(shortcode_atts(array(
'url' => '',
'autoplay' => '',
'volume' => '',
'class' => '',
'loops' => '',
), $atts));
if (empty($url)) {
return '<div style="color:red;font-weight:700;">ERROR!</div>';
}
if (empty($volume)) {
$volume = '80';
}
if (empty($class)) {
$class = "player_container";
}
/** Set default container class */
if (empty($loops)) {
$loops = "false";
}
$parent_title = get_the_title( $post->post_parent );
/** check if the post has a Post Thumbnail assigned to it*/
if ( has_post_thumbnail() ) {
$thumbnail = the_post_thumbnail();
}
else {
$thumbnail = 'http://demo.link/i.jpg';
}
$player_cont = '<div class="' . $class . '">';
$player_cont .= '
<div id="player-1" class="light">
<div style="display:none;" class="playerData">
{"name":"'.$parent_title.'","size":{"width":"100%","height":"100%"},"media":{"mp3":"' .$url.'","poster":"'.$thumbnail.'"}}
</div>
</div></div>';
return $player_cont;
}
The above code shows the audio player in the post content/entry, but I want to add this player on the post title as format:
Audio player (here I want to execute the
do_shortcode
function)Post title
Post content/entry (here I included a shortcode
[jplayer url="http://my.link"]
)
To do this, I inserted a shortcode [jplayer url="http://my.link"]
in the post content/entry, and execute do_shortcode
in my theme like this:
<?php echo do_shortcode('[jplayer url="'.$variable_parameter.']'); ?>
I also tried many codes:
<?php echo do_shortcode('[jplayer url="'.get_post_meta('post->ID', 'url', true).'"]') ?>
and tried with get_post_custom()
I'm a wordpress beginner, so I'm facing with many problems but I love designing website. Please correct the code or guide me the right way. Thanks very much.