arie_cristianD

adding download podcast button

Aug 9th, 2026
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. if ( ! function_exists( 'jnews_append_podcast_download_button_to_content' ) ) {
  2.     /**
  3.      * Tambahkan tombol download podcast pada akhir konten single post.
  4.      *
  5.      * @param string $content Konten post.
  6.      *
  7.      * @return string
  8.      */
  9.     function jnews_append_podcast_download_button_to_content( $content ) {
  10.         if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
  11.             return $content;
  12.         }
  13.  
  14.         $post_id               = get_the_ID();
  15.         $jnews_podcast_option = get_post_meta( $post_id, 'jnews_podcast_option', true );
  16.         $enable_podcast       = isset( $jnews_podcast_option['enable_podcast'] ) && '1' === $jnews_podcast_option['enable_podcast'];
  17.         $upload_url           = isset( $jnews_podcast_option['upload'] ) ? $jnews_podcast_option['upload'] : '';
  18.  
  19.         if ( ! $enable_podcast || empty( $upload_url ) ) {
  20.             return $content;
  21.         }
  22.  
  23.         $button = sprintf(
  24.             '<div class="jeg_podcast_download_wrapper"><a class="jeg_button jeg_btn_normal" href="%1$s" download target="_blank" rel="noopener">%2$s</a></div>',
  25.             esc_url( $upload_url ),
  26.             esc_html__( 'Download Podcast', 'jnews' )
  27.         );
  28.  
  29.         return $content . $button;
  30.     }
  31. }
  32.  
  33. add_filter( 'the_content', 'jnews_append_podcast_download_button_to_content', 999 );
Advertisement
Add Comment
Please, Sign In to add comment