Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have downloaded an audio player plugin for WP. the syntax is very simple. You just add the line [audio:my_file.mp3] to your post editor/excerpt, and call it in the loop with the_content() or the_excerpt() respectively.

I would like to build a metabox in which the user would upload a file, and the plugin syntax would automatically be generated accordingly. I know how to insert the meta-data into the DB, but pulling it with get_post_meta() or the_meta() just gets the syntax as it is, without replacing it with the desired plugin content (i.e the audio player).

I thought about dynamically injecting the syntax to the editor/excerpt with the use of the filter default_content but this filter only applies to normal posts, whereas mine is a custom post type (audio). your ideas are most welcomed.

share|improve this question
add comment

1 Answer 1

Sounds like a custom TinyMCE button would be the ideal candidate for the job.

WordPress has an excellent write-up in the codex on how to create one; you'd essentially add a button to the TinyMCE toolbar with your own callback, which could trigger a modal pop-up to choose the audio file & insert the shortcode automatically.

Equally, you could hook into the output of media items once they've been uploaded, and display a link that would inject the shortcode for that item into the post (if uploaded within the Thickbox pop-up) - akin to how featured thumbnails work.

Check out get_media_item() and get_attachment_fields_to_edit() in wp-admin/includes/media.php for available hooks and filters.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.