Skip to content

Instantly share code, notes, and snippets.

View jayseventwo's full-sized avatar

jayseventwo jayseventwo

View GitHub Profile
@jayseventwo
jayseventwo / add custom menu to page using shortcode
Created May 29, 2013 07:07
Add a WordPress custom menu to a page/post using a shortcode - add to functions.php
/* --------------------------------------------------add custom menu to page using shortcode
add [custommenu menu=Menu-name-here] to page*/
function custom_menu_shortcode( $atts, $content = null ) {
extract( shortcode_atts(
array(
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
@jayseventwo
jayseventwo / Custom widget area
Created May 23, 2013 04:58
Create a custom widget area.
// add to functions.php
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Right header',
'id' => 'custom-widget-01',
'description' => 'Widget Area',
'before_widget' => '<div id="one" class="two">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
@jayseventwo
jayseventwo / Create custom taxonomy
Created May 15, 2013 03:22
Create custom taxonomy - add to functions.php
/*-------------------------------------------------------------------------skills for portfolio custom post type -*/
register_taxonomy("Skills", array("portfolio"), array("hierarchical" => true, "label" => "Skills", "singular_label" => "Skill", "rewrite" => true));
@jayseventwo
jayseventwo / Display WordPress categories
Last active December 17, 2015 06:39
Display WordPress categories - add to functions.php
class DisplayCategoriesWidget extends WP_Widget
{
function DisplayCategoriesWidget()
{
$widget_ops = array('classname' => 'DisplayCategoriesWidget', 'description' => 'Displays categories' );
$this->WP_Widget('DisplayCategoriesWidget', 'Display Categories Widget', $widget_ops);
}
function form($instance)
{
@jayseventwo
jayseventwo / Shortcodes in sidebar (text) widgets
Created May 11, 2013 04:42
Shortcodes in sidebar (text) widgets
// Shortcodes in sidebar (text) widgets
//
add_filter('widget_text', 'do_shortcode', 11);
@jayseventwo
jayseventwo / Remove autop from WordPress pages
Created May 5, 2013 07:32
Remove autop from WordPress pages. Make sure you have “custom fields displaying from screen menu at top of page. Add to functions.php
function disable_autop() {
global $post;
$disable_autop_var = get_post_meta($post->ID, 'disable_autop', TRUE);
if ( !empty( $disable_autop_var ) ) {
remove_filter('the_content', 'wpautop');
}
}
add_action ('loop_start', 'disable_autop');
@jayseventwo
jayseventwo / WordPress Roots theme - Remove sidebar from front page
Created April 24, 2013 04:04
Remove sidebar from front page of WordPress Roots theme. Add to custom.php
<?php
if (is_front_page()) {
} else {
get_sidebar();
}
?>
@jayseventwo
jayseventwo / WordPress - Link featured image to larger version
Created April 24, 2013 04:02
Link post thumbnail (such as featured image) to larger version.
@jayseventwo
jayseventwo / Custom size images in WordPress
Created April 24, 2013 04:01
Create a custom size for your new image uploads. Add to functions.php
// custom image size for slider
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'new-size', 900, 400, true ); //(add new size here)
}
add_filter('image_size_names_choose', 'my_image_sizes');
function my_image_sizes($sizes) {
$addsizes = array(
"new-size" => __( "New Size")
@jayseventwo
jayseventwo / WordPress - fix nav menu highlighting issue when using custom post type
Created April 24, 2013 04:00
Fix nav menu issues with custom post types. If, when you link to a custom post type in your nav menu, the blog page also highlights the nadd the following to your functions.php, where "menu-portfolio" is the name of the nav menu item you need to fix.
function fix_portfolio_parent($menu){
global $post;
if ( 'portfolio' == get_post_type() )
{
$menu = str_replace( 'current_page_parent', '', $menu ); // remove all current_page_parent classes
$menu = str_replace( 'menu-portfolio', 'current_page_parent menu-portfolio', $menu ); // add the current_page_parent class to the page you want
}
return $menu;
}
add_filter( 'nav_menu_css_class', 'fix_portfolio_parent', 0 );