MP3 Icon/Image - change so that it is shown when shared on social media (2 posts)

  1. MCM
    Posted 3 years ago #

    1. Is it possible to change the MP3 Icon/Image?

    2. Alsp, to enforce that it is shown on Social Media sites like Facebook when users share the link?

    I googled and apparently one requires this code
    echo '<meta property="og:image" content="' . $default_image . '"/>';


  2. ntm
    Plugin Author

    Posted 3 years ago #

    Is it possible to change the MP3 Icon/Image?

    Yes. You could replace the image file or you could use a filter plugin which uses the podPress Action Hook podpress_downloadlinks which you can use to filter the output code of podPress for the lines with these icons/buttons and the download links.

    Alsp, to enforce that it is shown on Social Media sites like Facebook when users share the link?

    I'm not very familiar with open graph protocol. But it is also possible to use the same podPress Action hook to add such a meta tag. Although it is better if you do not use the echo command in filters. Filter functions get a value which gets modified inside the function. At the end a filter function returns the modified value.

    The code for a filter plugin which does both things could look like this:

    Plugin Name: podPress media file icon filter
    Plugin URI:
    Description: exchanges the default download icon of a certain media file type
    Author: ntm
    Version: 1.0
    Author URI:
    add_filter('podpress_downloadlinks', 'customize_podpress_downloadlinks');
    function customize_podpress_downloadlinks($podPressDownloadlinks) {
    	// If the current download links code is related to a mp3 file then it contains the phrase "podPress_downloadlinks_audio_mp3". Start the actions only in that case
    	if (FALSE !== stripos($podPressDownloadlinks, 'podPress_downloadlinks_audio_mp3')) {
    		$default_image_url = plugins_url('podpress').'/images/audio_mp3_button.png';
    		$custom_image_url = plugins_url('audio_mp3_button.png', __FILE__); // in case the new button file is in the same folder as this plugin
    		$podPressDownloadlinks = str_replace($default_image_url, $custom_image_url, $podPressDownloadlinks);
    		$podPressDownloadlinks .= "\n".'<meta property="og:image" content="' . $custom_image_url . '"/>'."\n";
    	return $podPressDownloadlinks;

    This code will replace the URL of the default mp3 download button with the URL of a button file with the same file which should be in the same folder as this plugin file.
    But if the button file is somewhere else then you can adjust the variable

    $custom_image_url = ...;

    e.g. with a hard-coded URL like this:

    $custom_image_url = 'http://example.com/myfolder/mynew_mp3_button.png';

    It also adds the open graph meta tag.

    All actions get only executed in case the given $podPressDownloadlinks string contains a certain phrase. For mp3 files it is podPress_downloadlinks_audio_mp3. For m4a files it would be podPress_downloadlinks_audio_m4a and for m4v file it would be podPress_downloadlinks_video_m4v. Only the last part changes according to the file type.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic