• I’m trying to get an audio player to display correctly in a WP custom post type, using a value from one of the meta fields and assembling the audio URL as follows:

    //output the audio link using ecpt_vnc_username
        function demo_audio_link () {
    
        	echo 'https://download.virtualnewscenter.com/demos/' .
        	do_shortcode('[ecpt_field id="anchor_username"]') . '.mp3';
        }
        add_action( 'genesis_entry_header', 'demo_audio_link', 11 );

    for anchor_username=aspector, the post renders the URL literally (https://download.virtualnewscenter.com/demos/aspector.mp3) rather than as an audio player.

    Page source looks like this:

    <header class="entry-header"><h1 class="entry-title" itemprop="headline">Alan Spector</h1>https://download.virtualnewscenter.com/demos/aspector.mp3<p class="entry-meta">

    I’ve tried various incantations of print, printf and echo, including the audio shortcode in what is echo’d ([audio src="https://download.virtualnewscenter.com/demos/aspector.mp3"], single vs. double quotes, and hard-coding the audio player as

    <audio class="wp-audio-shortcode" preload="none" style="width: 100%; visibility: hidden;" controls="controls"><source type="audio/mpeg" src="https://download.virtualnewscenter.com/demos/aspector.mp3"/></audio><br/>

    All of them end up with the literal outputting to the page, not being handled by the WP parsing to either a link or an audio player.

    What am I missing?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Oembed isn’t set up to filter genesis_entry_header as it is the_content, so you’ll need to run it yourself (the same as you’re running do_shortcode()).

    Untested, but try:

    add_action( 'genesis_entry_header', 'demo_audio_link', 11 );
    function demo_audio_link () {
    	$file = do_shortcode('[ecpt_field id="anchor_username"]') . '.mp3';
    	$url = 'https://download.virtualnewscenter.com/demos/' . $file;
    	echo wp_oembed_get( $url );
    }
    Thread Starter ksstormmedia

    (@ksstormmedia)

    Gary, thank you for the lead. I’m still stuck, but here’s where I’ve gotten:

    function demo_audio_link () {
    	$embed_code = wp_oembed_get('https://www.youtube.com/watch?v=_MSuePnvymo');
    	echo $embed_code ;
    	$file = do_shortcode('[ecpt_field id="anchor_username"]') . '.mp3';
    	$url = 'https://download.virtualnewscenter.com/demos/' . $file;
    	$embed_code1 = wp_oembed_get('$url');
    	echo "->" . $embed_code1 . "<-" ;
    	echo "->>" . $url . "<<-";
    }

    The first version, with $embed_code, is copy/paste from the Codex with a valid Youtube file. It works beautifully.

    The second version, with $embed_code1, does not work. The two “show me what you’re doing” lines at the end output
    -><- and
    ->>https://download.virtualnewscenter.com/demos/aspector.mp3<<-
    respectively. So $url is getting constructed correctly, but the embed code is not being generated.

    If I hard-code the URL in the wp_oembed_get, that does not generate the audio player either. If I put the YouTube link in the $url line, it works fine.

    I’m at a loss. Seems like there’s different behavior if it’s an mp3.

    Thread Starter ksstormmedia

    (@ksstormmedia)

    My last sentence triggered an idea…and it led to the solution. For the MP3, calling wp_aduio_shortcode directly was the answer. Here is the working code:

    function demo_audio_link () {
    	$file = do_shortcode('[ecpt_field id="anchor_username"]') . '.mp3';
    	$url = 'https://download.virtualnewscenter.com/demos/' . $file;
    	$attr = array(
    		'src'      => $url,
    		'loop'     => '',
    		'autoplay' => '',
    		'preload'  => 'auto'
    		);
    
    	$player = wp_audio_shortcode( $attr );
    	echo $player;
    }

    Gary, thank you again for the initial lead!

    Scott

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Audio shortcode or URL in custom post tremplate not rendering’ is closed to new replies.