Skip to content

Instantly share code, notes, and snippets.

View jfeliweb's full-sized avatar
🖖
Love, Peace and Happiness

Jean Felisme jfeliweb

🖖
Love, Peace and Happiness
View GitHub Profile
@jfeliweb
jfeliweb / home-single-loop-archive
Created January 28, 2015 17:49
Branded Image as the Default Fallback
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
<?php } ?>
@jfeliweb
jfeliweb / archive-loop-home
Created January 28, 2015 17:47
Set a Default Fallback Image for WordPress Post Thumbnails
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) {
echo get_the_post_thumbnail($post->ID);
} else {
echo main_image();
} ?>
//To get a search form into the right menu by default:
// the right top bar
function foundation_top_bar_r() {
$menu = wp_nav_menu(array(
'echo' => false,
'container' => false, // remove nav container
'container_class' => '', // class of container
'menu' => '', // menu name
@jfeliweb
jfeliweb / Removing Meta Boxes
Created October 16, 2014 17:31
Removing Post Meta Boxes from Posts and Pages
// REMOVE POST META BOXES
function remove_metaboxes() {
/* Posts */
remove_meta_box( 'authordiv','post','normal' ); // Author Metabox
remove_meta_box( 'commentstatusdiv','post','normal' ); // Comments Status Metabox
remove_meta_box( 'commentsdiv','post','normal' ); // Comments Metabox
remove_meta_box( 'postcustom','post','normal' ); // Custom Fields Metabox
@jfeliweb
jfeliweb / Can't Touch This Author
Created October 16, 2014 17:28
Restrict Authors to Edit Only Their Own Posts and Media
/* Only See Own Attachments */
add_action('pre_get_posts','users_attachments');
function users_attachments( $wp_query_obj ) {
global $current_user, $pagenow;
if( !is_a( $current_user, 'WP_User') )
return;
@jfeliweb
jfeliweb / Removing WordPress Version Number
Created October 16, 2014 17:26
Removing WordPress Version Number
remove_action('wp_head', 'wp_generator');
@jfeliweb
jfeliweb / Content Length Using A Custom Function
Created October 16, 2014 17:24
Controlling Content Length Using A Custom Function
/*************************************************************************
The following function takes two parameters:
$string – The string that needs be limited for example get_the_excerpt().
$max_words – The maximum amount of words you would like to show.
***************************************************************************/
/* Limit Your Website Excerpt */
function word_limit($string, $max_words){
@jfeliweb
jfeliweb / Excerpt Length
Created October 16, 2014 17:21
Controlling Excerpt Length Using Filters
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
@jfeliweb
jfeliweb / Create Multiple Search Functions for Everything
Created October 10, 2014 22:02
Create multiple Search functions for posts & custom post types and everything
/* Search Everything*/
function SearchFilter($query) {
$post_type = $_GET['post_type'];
if (!$post_type) {
$post_type = 'any';
}
if ($query->is_search) {
$query->set('post_type', $post_type);
};
return $query;
@jfeliweb
jfeliweb / Numbered Page Navigation
Created October 10, 2014 21:45
Numbered Page Navigation
<!-- Paging Start -->
<div class="paging">
<ul>
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
$args = array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?page=%#%',
'total' => $wp_query->max_num_pages,