Created
July 13, 2013 09:41
-
-
Save jeremejazz/5990184 to your computer and use it in GitHub Desktop.
Play Audio in WordPress Excerpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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