Skip to content

Instantly share code, notes, and snippets.

@jeherve
Created September 19, 2013 14:14
Show Gist options
  • Save jeherve/6624124 to your computer and use it in GitHub Desktop.
Save jeherve/6624124 to your computer and use it in GitHub Desktop.
[Jetpack] Mobile Theme Featured images on single views too
<?php
/*
* Plugin Name: Mobile Theme Featured images on single views too
* Plugin URI: http://wordpress.org/extend/plugins/jetpack-mobile-theme-featured-images/
* Description: Adds Featured Images before the content on the article pages, in Jetpack Mobile theme
* Author: Jeremy Herve
* Version: 1.0
* Author URI: http://jeremyherve.com
* License: GPL2+
* Text Domain: jetpack
*/
// Check if we are on mobile
function matteholm_is_mobile() {
// Are Jetpack Mobile functions available?
if ( ! function_exists( 'jetpack_is_mobile' ) )
return false;
// Is Mobile theme showing?
if ( isset( $_COOKIE['akm_mobile'] ) && $_COOKIE['akm_mobile'] == 'false' )
return false;
return jetpack_is_mobile();
}
// Let's add the post thumbnail, but only if we're on a mobile device and on a single page
function matteholm_maybe_add_filter() {
// On mobile, and on an article page?
if ( matteholm_is_mobile() && '1' == get_option( 'wp_mobile_featured_images' ) && is_single() )
add_filter( 'the_content', 'jetpackme_single_featured_image' );
}
add_action( 'wp_head', 'matteholm_maybe_add_filter' );
// Build the function
function jetpackme_single_featured_image( $content ) {
$featured_image = jeherve_single_thumb();
if( is_admin() || !in_the_loop() )
return $content;
return $featured_image . $content;
}
function jeherve_single_thumb() {
global $post;
if ( !$post )
return;
$post_id = $post->ID;
$thumb = get_the_post_thumbnail( $post_id );
echo '<div class="entry-thumbnail">' . $thumb . '</div><!-- .entry-thumbnail -->';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment