Skip to content

Instantly share code, notes, and snippets.

View FernE97's full-sized avatar

Eric Fernandez FernE97

View GitHub Profile
@FernE97
FernE97 / dynamic_excerpt.php
Created February 23, 2012 20:37
PHP: WordPress Dynamic Excerpt
<?php
function the_excerpt_dynamic($num_words) {
global $post;
$text = $post->post_excerpt;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters( 'the_content', $text );
$text = str_replace( ']]>', ']]>', $text );
}
@FernE97
FernE97 / slides.php
Created March 6, 2012 23:02
PHP: WordPress Slides
<ul class="slides">
<?php
$args = array(
'post_type' => 'slide',
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => 3
);
$slides = get_posts( $args );
@FernE97
FernE97 / header.php
Created March 7, 2012 00:16
html: WordPress Head
<!doctype html>
<!--[if IE 6 ]> <html <?php language_attributes(); ?> class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html <?php language_attributes(); ?> class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html <?php language_attributes(); ?> class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html <?php language_attributes(); ?> class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html <?php language_attributes(); ?> class="no-js"> <!--<![endif]-->
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<title><?php wp_title( '|', true, 'right' ); bloginfo( 'name' ); ?></title>
@FernE97
FernE97 / ir.css
Created March 7, 2012 18:40
css: Image Replacement
/* For image replacement */
.ir {
border:0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}
@FernE97
FernE97 / clearfix.css
Created March 7, 2012 18:43
css: clearfix
/* Contain floats: h5bp.com/q */
.group:before, .group:after { content: ""; display: table; }
.group:after { clear: both; }
.group { *zoom: 1; }
@FernE97
FernE97 / shortcode.php
Created March 7, 2012 21:47
PHP: WordPress Shortcode
<?php
add_shortcode( 'basic_shortcode', 'basic_shortcode' );
function basic_shortcode($atts) {
$atts = shortcode_atts(
array(
'title' => 'My Shortcode'
), $atts);
ob_start();
@FernE97
FernE97 / custom_post.php
Created March 9, 2012 05:08
PHP: WordPress Custom Post Type
<?php
function register_cpt_slides() {
$post_type = 'slides';
$labels = array(
'name' => _x( 'Slides', $post_type ),
'singular_name' => _x( 'Slide', $post_type ),
'add_new' => _x( 'Add New', $post_type ),
@FernE97
FernE97 / custom_field.php
Created March 9, 2012 19:00
PHP: WordPress Custom Field
<?php
// Custom fields
if ( get_post_meta( $post->ID, 'custom_01', true ) ) {
echo get_post_meta( $post->ID, 'custom_01', true );
}
@FernE97
FernE97 / placeholder.js
Created March 9, 2012 19:18
JS: jQuery Fallback Placeholder
// Add input placeholder for older browsers
(function ($) {
"use strict";
if (!Modernizr.input.placeholder) {
$('[placeholder]').focus(function () {
var input = $(this);
if (input.val() === input.attr('placeholder')) {
input.val('');
@FernE97
FernE97 / add_meta_box.php
Created March 9, 2012 20:34
PHP: WordPress Custom Meta Box
<?php
// custom meta box
add_action( 'admin_menu', 'create_meta_box' );
add_action( 'save_post', 'save_meta_box' );
function create_meta_box() {
// add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args );
add_meta_box( 'new_meta_box', 'Meta Box Title', 'new_meta_box', 'post_type', 'side', 'low' );
}