Skip to content

Instantly share code, notes, and snippets.

@pixelcoder
pixelcoder / jquery.app.js
Created July 21, 2017 19:04
Tidy up GET requests with jQuery
$('form').on('submit', function(e) {
$.each($('select'), function(i, v) {
$.each($('select option:selected'), function(i, v) {
if($(this).val() === ''){
$(this).parent('select').prop('disabled', true);
}
@pixelcoder
pixelcoder / init.buddypress.php
Created June 28, 2016 22:47
BuddyPress: Disable TinyMce on front
# Disable TINYMCE on XPROFILE
function antipole_remove_rich_text() {
return false;
}
add_filter('bp_xprofile_is_richtext_enabled_for_field', 'antipole_remove_rich_text');
@pixelcoder
pixelcoder / shortcodes.php
Created May 26, 2016 22:17
Example WordPress shortcode creation
<?php
# BUTTONS
function sc_btn_default($atts, $content = null){
return '<a href="'.$atts['link'].'" class="button">'.do_shortcode($content).'</a>';
}
add_shortcode('button', 'sc_btn_default');
function sc_btn_primary($atts, $content = null){
return '<a href="'.$atts['link'].'" class="button">'.do_shortcode($content).'</a>';
}
add_shortcode('button_primary', 'sc_btn_default');
@pixelcoder
pixelcoder / app.js
Last active August 29, 2015 14:21
YouTube API v3: Get Playlist
var channelName = 'newformat_is_ID_not_pretty_permalink';
var vidWidth = 525;
var vidHeight = 325;
var vidResults = 6;
jQuery.get(
"https://www.googleapis.com/youtube/v3/channels", {
part: 'contentDetails',
forUsername: channelName,
key: '[API KEY]'
}, function(data){
@pixelcoder
pixelcoder / header.php
Created April 20, 2015 03:49
WordPress: Call menu
<?php
$defaults = array(
'theme_location' => 'wp-primary-menu',
'container' => false,
'items_wrap' => '<ul class="wp-primary-menu">%3$s</ul>'
);
wp_nav_menu($defaults);
?>
@pixelcoder
pixelcoder / init.php
Created April 20, 2015 03:49
WordPress: Register menus
# Register menus
function px_register_menus(){
register_nav_menus(array(
'wp-primary-menu' => __('Primary WordPress Menu'),
'wp-footer-menu' => __('Footer WordPress Menu')
));
}
add_action('init', 'px_register_menus');
@pixelcoder
pixelcoder / init.php
Created April 20, 2015 03:48
WordPress: Register sidebar
# Register Sidebar
$args = array(
'name' => __('Sidebar', 'nantre'),
'id' => 'wp-sidebar',
'description' => 'Add widgets to the sites Sidebar, all default WordPress widgets are supported',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
);
@pixelcoder
pixelcoder / sidebar.php
Created April 20, 2015 03:46
WordPress: Dynamic sidebar
<?php if(dynamic_sidebar('wp-sidebar')) : else : ?>
<div class="widget widget_search">
<h4>Search</h4>
<?php get_search_form(); ?>
</div><!-- END WIDGET -->
<div class="widget widget_categories">
<h4>Categories</h4>
<ul>
<?php wp_list_categories('title_li='); ?>
</ul>
@pixelcoder
pixelcoder / init.php
Created April 20, 2015 03:44
WordPress: Get rid of wp_head() junk
# Remove junk
function px_wp_remove_head() {
remove_action('wp_head', 'feed_links');
remove_action('wp_head', 'feed_links_extra');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
remove_action('wp_head', 'locale_stylesheet');
remove_action('wp_head', 'noindex');
remove_action('wp_head', 'wp_print_styles');
@pixelcoder
pixelcoder / index.php
Created April 20, 2015 03:42
WordPress: Get sticky posts
<?php
$sticky = get_option('sticky_posts');
$args = array(
'posts_per_page' => 6,
'post__in' => $sticky
);
$px_query = new WP_Query($args);
?>
<?php if(!empty($sticky)) : ?>
<?php while($px_query->have_posts()) : $px_query->the_post(); ?>