• I would like to edit the code that’s inserted when selecting “Embed Media Player” as the “Attachment Display Settings” when uploading a song to a blog post.

    Right now the code that’s inserted is:
    [audio mp3="song url"][/audio]

    I would like to add a text and a link before the actual audio player. The song URL should be inserted as a direct link and then as an audio player. The text for the link should be based on the post title (“Artist – Song title”). The code would look like this:

    <strong>MP3:</strong> <a href="song url">Artist - Song title</a>
    [audio mp3="song url"][/audio]

    How would I do this the easiest way?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Something like this would work:

    add_filter( 'media_send_to_editor', 'mp3_media_insert', 20, 3 );
    function mp3_media_insert( $html, $id, $attachment ){
    	$output = '';
    	$post = get_post( $id );
    	if ( 'audio/mpeg' == $post->post_mime_type ) {
    		$output .= '<strong>MP3:</strong>';
    		$output .= '<a href="'.$attachment[url].'">'.$post->post_title.'</a>';
    		$output .= $html;
    		return $output;
    	} else {
    		return $html;
    	}
    }
    Thread Starter tobbger

    (@tobbger)

    Thank you so much! I’ll try it. Where do I enter the code?

    Insert the codes in your theme’s functions.php file…

    Thread Starter tobbger

    (@tobbger)

    Brilliant! Everything is working except for one thing. The text placed in-between the <a> tags are now based on the song title of the MP3. I would like the text to be based on the blog post title that I write in the editor as a title for the post itself.

    Really appreciate your help! Thank you!

    Ok… What you are asking for,is a little bit tricky. We will need to create a javascript file plus add more codes to the functions.php file. Just to make it easy for you, I have inserted the whole stuff inside a simple plugin.Please download the plugin here, remove the previous code you inserted in your functions.php,activate the plugin and report your results.
    A couple of things you need to know, if the post title is empty while inserting the mp3 file, let’s say writing a new post, the plugin would default to the mp3 title as the anchor text. Also Anytime the post title is edited, the plugin records the changes and therefore insert the edited post title as the anchor text…

    Thread Starter tobbger

    (@tobbger)

    Wow! You’re the best! I’ll try this and get back to you with the results.

    Thank you so much once again!

    Thread Starter tobbger

    (@tobbger)

    Works likes a charm! Incredible! Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Edit "Attachment Display Settings"’ is closed to new replies.