Skip to content

Instantly share code, notes, and snippets.

@msaari
Created April 5, 2019 04:12
Show Gist options
  • Select an option

  • Save msaari/af8ee093fd4857594ca96baf37cc69d0 to your computer and use it in GitHub Desktop.

Select an option

Save msaari/af8ee093fd4857594ca96baf37cc69d0 to your computer and use it in GitHub Desktop.
PDF icons for GeneratePress
<?php
/**
* Add this to your theme functions.php (or preferably in a custom plugin, because a theme
* update will overwrite the functions.php.
*
* You can also try different locations by replacing the 'generate_before_entry_title' with
* one of the following:
*
* - generate_after_entry_title
* - generate_before_content
* - generate_after_entry_header
*/
add_action( 'generate_before_entry_title', 'rlv_add_mime_icon' );
function rlv_add_mime_icon() {
$pdf_icon = 'https://cdn4.iconfinder.com/data/icons/file-extensions-1/64/pdfs-128.png'; // Add the URL to your PDF icon here.
if ( is_search() ) {
global $post;
if ( 'application/pdf' === $post->post_mime_type ) {
echo "<img class='file-icon pdf' src='$pdf_icon' alt='PDF' />";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment