Skip to content

Instantly share code, notes, and snippets.

Avatar

Brad Williams braginteractive

View GitHub Profile
@braginteractive
braginteractive / last-post.php
Last active Aug 29, 2015
Add class to the last WordPress post
View last-post.php
/**
* 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 Jun 30, 2015
Sample Meta Box for WordPress
View color-picker.js
jQuery(document).ready(function($){
$('.meta-color').wpColorPicker();
});
@braginteractive
braginteractive / posts-with-images-widget.php
Created Jun 30, 2015
Displays posts with featured images in WordPress widget
View posts-with-images-widget.php
<?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 Jul 9, 2015
Add class to posts navigation links for WordPress
View post-navigation-filter.php
/**
* 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 Jul 9, 2015
Add a class to each tag in WordPress
View tag-classes.php
<?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 Aug 29, 2015
Custom Read More button for WordPress
View read-more-btn.php
/**
* 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 Jul 11, 2015
Remove .DS_Store file and zip
View remove-ds_store.txt
zip -r bar.zip bar -x "*.DS_Store"
@braginteractive
braginteractive / post.js
Created Jul 22, 2015
Console log POST data in PHP
View post.js
<script>
console.log(<?php echo json_encode($_POST); ?>);
</script>
@braginteractive
braginteractive / wp-jquery-wrapper.js
Created Jul 22, 2015
jQuery wrapper for WordPress
View wp-jquery-wrapper.js
jQuery(document).ready(function($){
});
@braginteractive
braginteractive / portfolio-customizer.php
Created Jul 27, 2015
Show customizer panel just on Portfolio archive page
View portfolio-customizer.php
<?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' ),