Skip to content

Instantly share code, notes, and snippets.

View aprakasa's full-sized avatar
🎯
Focusing

Arya Prakasa aprakasa

🎯
Focusing
View GitHub Profile
@aprakasa
aprakasa / gist:3729495
Created September 15, 2012 19:56
Exclude category from feed
/** Exclude category from feed */
function excludecatfeed($query) {
if(is_feed()) {
$query->set('category__not_in','-1');
return $query;
}
}
add_filter('pre_get_posts', 'excludecatfeed');
@aprakasa
aprakasa / gist:3774281
Created September 24, 2012 05:11
Simple social share
<!-- Twitter share -->
<a href="http://twitter.com/?status=<?php the_title(); ?>%20<?php echo wp_get_shortlink(get_the_ID()); ?>" onclick="window.open(this.href); return false;">TWITTER</a>
<!-- Facebook -->
<a href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&amp;t=<?php the_title(); ?>" onclick="window.open(this.href); return false;">FACEBOOK</a>
<!-- Google plus -->
<a href="https://plus.google.com/share?url=<?php the_permalink();?>" onclick="javascript:window.open(this.href,'', 'menubar=no, toolbar=no, resizable=yes, scrollbars=yes,height=600,width=600');return false;">Google plus</a>
<!-- Pinterest -->
@aprakasa
aprakasa / gist:3780367
Created September 25, 2012 06:58
wp_editor() and Genesis Admin Page
<?php
class Test_Setting_Admin extends Genesis_Admin_Boxes {
/**
* Create an admin menu item and settings page.
*
* @since 1.0
*/
function __construct() {
@aprakasa
aprakasa / gist:3935970
Created October 23, 2012 00:50
get attachment ID based on src
/**
* This is helper function will get attachment ID based on src
*
* @see http://wordpress.org/support/topic/need-to-get-attachment-id-by-image-url
*/
function get_attachment_id_from_src( $url ) {
global $wpdb;
$id = url_to_postid( $url );
if( $id == 0 ) {
@aprakasa
aprakasa / WooCommerce - Display Category Image
Created December 2, 2012 09:10
WooCommerce - Display Category Image
// verify that this is a product category page
if (is_product_category()){
global $wp_query;
// get the query object
$cat = $wp_query->get_queried_object();
// get the thumbnail id user the term_id
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
// get the image URL
$image = wp_get_attachment_url( $thumbnail_id );
// print the IMG HTML
@aprakasa
aprakasa / gist:4242702
Created December 9, 2012 00:23
Redirect theme/plugin after activation
<?php
add_action( 'init', 'ayo_redirect_plugin_activation' );
function ayo_redirect_plugin_activation(){
global $pagenow;
if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'plugins.php' )
wp_redirect( admin_url( 'options-general.php?page=plugin-page-slug' ) );
exit;
}
@aprakasa
aprakasa / gist:4264372
Created December 12, 2012 02:34
Using transients on a single loop inside WordPress
<?php
/**
* Using transients on a single loop inside WordPress
*
* @link http://speckyboy.com/2011/12/14/website-speed-part-3-caching-wordpress/
* /
$loop = get_transient( 'loop' );
if ( false === $loop ) {
// Show the last 100 tweets from the custom post type tweets.
<?php
/**
* Caching Widgets with transients
*
* @link http://speckyboy.com/2011/12/14/website-speed-part-3-caching-wordpress/
* /
class show_ak_events_Widget extends WP_Widget {
function show_ak_events_Widget() {
/* Widget settings. */
<?php
/**
* Using caching for theme options
* @link http://speckyboy.com/2011/12/14/website-speed-part-3-caching-wordpress/
* /
function my_get_cache_option($option_name = 'ThemeAdminOptions' ){
// get wanted transient
$value = get_transient( $option_name );
// check if it has any content
if(false === $value){
@aprakasa
aprakasa / gist:4264393
Created December 12, 2012 02:40
automatically echo to the screen
<?php
/**
* automatically echo to the screen using transient
*
* @link http://speckyboy.com/2011/12/14/website-speed-part-3-caching-wordpress/
* /
$loop_output = get_transient( 'loopOutput' );
if ( false === $loop_output ) {