• Resolved Faisal Ahmed

    (@fftfaisal)


    I will try to add download button into wp_audio_shortcode() function using filters. but the download button is outside of html output. In my site i want to hide auio player fault it will show after a text click . that’s why I need download button inside html output mark up . I will share my code right now.

    add_filter( 'wp_audio_shortcode', 'ast_audio_shortcode_enhancer', 10, 5 );
    function ast_audio_shortcode_enhancer( $html, $atts, $audio, $post_id, $library, $content ) {
        $audio_types = array( 'mp3', 'ogg', 'wma', 'm4a', 'wav' );
        // Use the first audio type that has data.
        foreach ( $audio_types as $extension ) {
            if ( strlen( $atts[ $extension ] ) ) {
                 $html .= sprintf( '
    <p class="download-file"><a href="%s">Download</a></p> ',$atts[ $extension ] );
                break;
    			
    				
            }
        }
        // Otherwise return the original html.
        return $html;
    }
    

    here is the output screenshot click here

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    The default HTML output is a self contained div. When you append your download link, naturally it’s outside the player div. To include it within the div, you need to strip off the terminal </div>, then append your download HTML, followed by the </div> you stripped off.

    Alternately, create a new container to hold everything, roughly something like:
    return '<div class="new">.$html.'<a href="link-here">download</a></div>';

    Thread Starter Faisal Ahmed

    (@fftfaisal)

    many many thank ?? ??

    Thread Starter Faisal Ahmed

    (@fftfaisal)

    one more .question I need to generate an ID for every div return like this code

    return '<div class="new" id="1">.$html.'<a href="link-here">download</a></div>';

    return '<div class="new" id="2">.$html.'<a href="link-here">download</a></div>';

    how to do that inside here

    Moderator bcworkz

    (@bcworkz)

    The post ID or any unique ID? I guess $post_id works either way
    return '<div class="new" id="'.$post_id.'">'.$html.'<a href="link-here">download</a></div>';

    Thread Starter Faisal Ahmed

    (@fftfaisal)

    ok . thanks again for reply ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘want to add download button on [audio] short code’ is closed to new replies.