Skip to content

Instantly share code, notes, and snippets.

View braginteractive's full-sized avatar

Brad Williams braginteractive

View GitHub Profile
@braginteractive
braginteractive / last-post.php
Last active August 29, 2015 14:23
Add class to the last WordPress post
/**
* Add 'last' class to last post
* Must be using <?php post_class(); ?>
*/
function add_last_class($classes) {
global $wp_query;
if(($wp_query->current_post + 1) == $wp_query->post_count)
$classes[] = 'last';
@braginteractive
braginteractive / color-picker.js
Created June 30, 2015 18:04
Sample Meta Box for WordPress
jQuery(document).ready(function($){
$('.meta-color').wpColorPicker();
});
@braginteractive
braginteractive / posts-with-images-widget.php
Created June 30, 2015 19:59
Displays posts with featured images in WordPress widget
<?php
// Creating the widget
class name_prefix_widget extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID of your widget
'name_prefix_widget',
// Widget name will appear in UI
__('Recent Posts with Image', 'text-domain'),
@braginteractive
braginteractive / post-navigation-filter.php
Created July 9, 2015 19:59
Add class to posts navigation links for WordPress
/**
* Filter to add class to next/previous navigation links
*/
function posts_link_attributes() {
return 'class="mdlwp-nav__button"';
}
add_filter('next_posts_link_attributes', 'posts_link_attributes');
add_filter('previous_posts_link_attributes', 'posts_link_attributes');
function post_link_attributes($output) {
@braginteractive
braginteractive / tag-classes.php
Created July 9, 2015 20:36
Add a class to each tag in WordPress
<?php
$tags = get_the_tags();
$html = '<div class="post_tags">';
foreach ($tags as $tag){
$tag_link = get_tag_link($tag->term_id);
$html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
$html .= "{$tag->name}</a>";
}
$html .= '</div>';
@braginteractive
braginteractive / read-more-btn.php
Last active August 29, 2015 14:24
Custom Read More button for WordPress
/**
* Custom Read More Button
*/
function modify_read_more_link() {
return '<br><a class="custom-more" href="' . get_permalink() . '">'. __( 'Read More', 'textdomain' ). '></a>';
}
add_filter( 'the_content_more_link', 'modify_read_more_link' );
@braginteractive
braginteractive / remove-ds_store.txt
Created July 11, 2015 00:58
Remove .DS_Store file and zip
zip -r bar.zip bar -x "*.DS_Store"
@braginteractive
braginteractive / post.js
Created July 22, 2015 19:20
Console log POST data in PHP
<script>
console.log(<?php echo json_encode($_POST); ?>);
</script>
@braginteractive
braginteractive / wp-jquery-wrapper.js
Created July 22, 2015 21:30
jQuery wrapper for WordPress
jQuery(document).ready(function($){
});
@braginteractive
braginteractive / portfolio-customizer.php
Created July 27, 2015 22:32
Show customizer panel just on Portfolio archive page
<?php
function prefix_customizer_register( $wp_customize ) {
$wp_customize->add_panel( 'panel_id', array(
'priority' => 10,
'capability' => 'edit_theme_options',
'theme_supports' => '',
'title' => __( 'Example Panel', 'textdomain' ),
'description' => __( 'Description of what this panel does.', 'textdomain' ),