Skip to content

Instantly share code, notes, and snippets.

@jeremejazz
Created July 13, 2013 09:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremejazz/5990184 to your computer and use it in GitHub Desktop.
Save jeremejazz/5990184 to your computer and use it in GitHub Desktop.
Play Audio in WordPress Excerpt
<?php
/*Add this code to
functions.php
From: http://premium.wpmudev.org/forums/topic/audio-preview-in-product-excerpt#post-280140
*/
function add_audio_to_excerpt( $excerpt ){
// get post
global $post;
// have post ID?
if ( !empty( $post->ID ) ) {
// get audio
$meta_value = get_post_meta( $post->ID, 'audio_source', true );
// have audio?
if ( !empty( $meta_value ) ) {
// do shortcode
$shortcode = do_shortcode( '[audio src="' . $meta_value . '"]' );
// have shortcode?
if ( !empty( $shortcode ) ) {
// append shortcode to content
$excerpt = $excerpt . $shortcode;
}
}
}
// return excerpt
return $excerpt;
}
// filter excerpt with above function
add_filter( "get_the_excerpt", add_audio_to_excerpt );
@ShayanFaghihi
Copy link

Hello friend,
I was using this great code on my theme, until I faced a huge "Error Log" on my cPanel host, saying "PHP Warning: Use of undefined constant add_audio_to_excerpt- assumed 'add_audio_to_excerpt' (this will throw an Error in a future version of PHP) in /public_html/wp-content/themes/Impreza-child/functions.php on line 74

Do you have any idea how I can fix this error?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment