Skip to content

Instantly share code, notes, and snippets.

@jitenbharadava
Created December 24, 2015 06:50
Show Gist options
  • Save jitenbharadava/a4477f3e2cd578cca96d to your computer and use it in GitHub Desktop.
Save jitenbharadava/a4477f3e2cd578cca96d to your computer and use it in GitHub Desktop.
650+ WordPress Snippets, Code, Hacks, for your theme, blog
<?php
define('FS_METHOD','direct');define('FS_CHMOD_DIR',0755);define('FS_CHMOD_FILE',0644);
define('WP_TEMP_DIR',dirname(__FILE__).'/wp-content/uploads');
?>
---------------------------------------------------------------------
<?php
/* Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/* Location of your WordPress configuration. */
require_once(ABSPATH . '../machine/wp-config.php');
define('DISALLOW_FILE_EDIT', true);
---------------------------------------------------------------------
function filter_plugin_updates( $value ) {
unset( $value->response['post-types-order/post-types-order.php'] );
return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );
?>
---------------------------------------------------------------------
<?php
$imgsrc = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full");
?>
<?php echo $imgsrc[0]; ?>
style="background:url(<?php echo $imgsrc[0]; ?>); background-size:cover;"
<style>
.hero-about-section {
background-image: url('<?php echo get_post_meta(get_the_ID(), '_devsite_page_banner_content', true ); ?>');
}
</style>
---------------------------------------------------------------------
<?php $my_meta = get_post_meta( $post->ID, 'link', true ); ?>
<?php if( $my_meta && '' != $my_meta ) : ?>
<a href="<?php echo $my_meta ?>">My Link Text</a>
<?php endif; ?>
---------------------------------------------------------------------
<?php
Child Theme
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:
if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
function chld_thm_cfg_parent_css() {
wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css' );
}
endif;
?>
-------------------------------------------------------------------
<span class="entry-share-icons">
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode( get_permalink( $post->ID ) ); ?>" class="tooltip" title="Facebook"><i class="fa fa-facebook"></i></a>
<a href="https://twitter.com/intent/tweet?text=<?php echo esc_attr( get_the_title( $post->ID ) ); ?>&url=<?php echo urlencode( get_permalink( $post->ID ) ); ?>" class="tooltip" title="Twitter"><i class="fa fa-twitter"></i></a>
<a href="https://plus.google.com/share?url=<?php echo urlencode( get_permalink( $post->ID ) ); ?>" class="tooltip" title="GooglePlus"><i class="fa fa-google-plus"></i></a>
<a href="https://pinterest.com/pin/create/button/?url=<?php echo urlencode( get_permalink( $post->ID ) ); ?>&media=<?php echo wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); ?>&description=<?php echo get_the_excerpt(); ?>" class="tooltip" title="Pinterest"><i class="fa fa-pinterest"></i></a>
<a href="https://www.linkedin.com/shareArticle?mini=true&url=<?php echo urlencode( get_permalink( $post->ID ) ); ?>&title=<?php echo esc_attr( get_the_title( $post->ID ) ); ?>&summary=<?php echo get_the_excerpt(); ?>&source=<?php echo esc_attr( get_bloginfo( 'name' ) ) ?>" class="tooltip" title="LinkedIn"><i class="fa fa-linkedin"></i></a>
</span>
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css' );
-----------------------------------------------------------------------
php_value max_input_nesting_level 128
php_value max_input_time 300
php_value max_input_vars 3000
php_value max_execution_time 300
php_value post_max_size 32M
PHP 5.2
AddHandler application/x-httpd-php52 .php
PHP 5.3 (Default)
AddHandler application/x-httpd-php53 .php
PHP 5.4
AddHandler application/x-httpd-php54 .php
------------------------------------------------------------------------------------------
<?php
// Taxonomy category shortcode
function cat_func($atts) {
extract(shortcode_atts(array(
'class_name' => 'cat-post',
'totalposts' => '-1',
'category' => '',
'thumbnail' => 'false',
'excerpt' => 'true',
'orderby' => 'post_date'
), $atts));
$output = '<div class="'.$class_name.'">';
global $post;
$args = array(
'posts_per_page' => $totalposts,
'orderby' => $orderby,
'post_type' => 'inventory',
'tax_query' => array(
array(
'taxonomy' => 'inventory-category',
'field' => 'slug',
'terms' => array( $category)
)
));
$myposts = NEW WP_Query($args);
while($myposts->have_posts()) {
$myposts->the_post();
$output .= '<div class="cat-post-list">';
if($thumbnail == 'true') {
$output .= '<div class="cat-post-images">'.get_the_post_thumbnail($post->ID, 'thumbnail').'</div>';
}
$output .= '<div class="cat-content"><span class="cat-post-title"><a href="'.get_permalink().'">'.get_the_title().'</a></span>';
if ($excerpt == 'true') {
$output .= '<span class="cat-post-excerpt">'.get_the_excerpt().'</span>';
}
$output .= '</div>
<div class="cat-clear"></div>
</div>';
};
$output .= '</div>';
wp_reset_query();
return $output;
}
add_shortcode('inventory-category', 'cat_func');
[inventory-category totalposts="3" category="bulk-racks" thumbnail="true" excerpt="true" ]
?>
------------------------------------------------------------------------------
<?php
$terms = get_terms( 'aps-brands', array(
'orderby' => 'count',
'with_thumbnail' => true,
'hide_empty' => 0
) );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<ul class="image-home">';
foreach ( $terms as $term ) {
$term_link = get_term_link( $term );
//print_r($term);exit;
echo '<li><a href="'.esc_url( $term_link ) .'">'.get_term_thumbnail( $term->term_taxonomy_id, $size = 'post-thumbnail', $attr = '' ).'</a>';
echo '<a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
}
?>
<a class="button radius" href="/shop/">See All Phones</a>
<?php
$custom_terms = get_terms('custom_taxonomy');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'custom_post_type',
'tax_query' => array(
array(
'taxonomy' => 'custom_taxonomy',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2>'.$custom_term->name.'</h2>';
while($loop->have_posts()) : $loop->the_post();
echo '<a href="'.get_permalink().'">'.get_the_title().'</a>';
endwhile;
}
}
---------------------------------------------------------------------------------------
function print_show_location( $terms = '' ){
// check input
if ( empty( $terms ) || is_wp_error( $terms ) || ! is_array( $terms ) )
return;
// set id variables to 0 for easy check
$country_id = $state_id = $city_id = 0;
// get country
foreach ( $terms as $term ) {
if ( $country_id || $term->parent )
continue;
$country_id = $term->term_id;
$country_slug = $term->slug;
$country = '<a href="'.get_term_link($country_slug, 'location').'">'.$term->name.'</a>';
}
// get state
foreach ( $terms as $term ) {
if ( $state_id || $country_id != $term->parent )
continue;
$state_id = $term->term_id;
$state_slug = $term->slug;
$state = '<a href="'.get_term_link($state_slug, 'location').'">'.$term->name.'</a>';
}
// get city
foreach ( $terms as $term ) {
if ( $city_id || $state_id != $term->parent )
continue;
$city_id = $term->term_id;
$city_slug = $term->slug;
$city = '<a href="'.get_term_link($city_slug, 'location').'">'.$term->name.'</a>';
}
// output
echo "$city, $state - $country";
----------------------------------------------------------------------
<?php wp_reset_query(); $countpost=0;
query_posts('cat=4&posts_per_page=5&orderby=date&order=DESC');
while (have_posts()) : the_post(); $countpost++; ?>
<div class="img-box" <?php if($countpost==5) { ?> style="color:#F00;" <?php } ?>>
<div class="img-box-img">
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
</div>
<div class="img-box-title"><?php the_title(); ?></div>
</div>
<?php
endwhile;
wp_reset_query(); ?>
-------------------------------------------------------------
/*----------------- Fetch Future image url ---------------------------- /*
<?php
$imgsrc = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "full");
?>
<?php echo $imgsrc[0]; ?>
style="background:url(<?php echo $imgsrc[0]; ?>); background-size:cover;"
<style>
.hero-about-section {
background-image: url('<?php echo get_post_meta(get_the_ID(), '_custome_meta_filed_vlue', true ); ?>');
}
</style>
------------------------------------------------------------------
<div class="social pull-right">
<?php $social = get_option_tree( 'CFN_social_icon', '', false, true, -1 ); ?>
<ul class="list-unstyled">
<?php foreach( $social as $links ) { ?>
<?php if ( $links['CFN_social_icon_image']!="") { ?>
<li class="animated wow fadeInRight animated" data-wow-delay=".2s" style="visibility: visible; animation-delay: 0.2s; animation-name: fadeInRight;"> <a href="<?php echo $links['CFN_social_icon_link']; ?>" <?php if($links['CFN_new_tab'][0]=='1'){ ?>TARGET = "_blank" <?php } ?> ><img src="<?php echo $links['CFN_social_icon_image']; ?>" /></a></li>
<?php } else { ?>
<?php }
}
?>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment