Skip to content

Instantly share code, notes, and snippets.

View rsharrer's full-sized avatar

Ryan Sharrer rsharrer

View GitHub Profile
@rsharrer
rsharrer / Add search form to specific wp_nav_menu.php
Created September 26, 2013 13:54
Add search form to specific wp_nav_menu
add_filter('wp_nav_menu_items', 'add_search_form', 10, 2);
function add_search_form($items, $args) {
if( $args->theme_location == 'MENU-NAME' )
$items .= '<li class="search"><form role="search" method="get" id="searchform" action="'.home_url( '/' ).'"><input type="text" value="search" name="s" id="s" /><input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" /></form></li>';
return $items;
}
@rsharrer
rsharrer / Facebook open graph snippet to set default image.php
Created September 26, 2013 13:53
Facebook open graph snippet to set default image
function diww_facebook_image() {
echo '<meta property="fb:admins" content="ADMIN_ID" />';
echo '<meta property="og:title" content="' . get_the_title() . '" />';
echo '<meta property="og:site_name" content="' . get_bloginfo('name') . '" />';
global $post;
if ( is_singular() ) { // only if a single post or page
echo '<meta property="og:type" content="article" />';
echo '<meta property="og:url" content="' . get_permalink() . '" />';
if (has_post_thumbnail( $post->ID )) { // use featured image if there is one
$feat_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
@rsharrer
rsharrer / Change default ‘Enter Title Here’ for custom post types.php
Created September 26, 2013 13:53
Change default ‘Enter Title Here’ for custom post types
function change_default_title( $title ){
$screen = get_current_screen();
if ( 'POST_TYPE' == $screen->post_type ) {
$title = 'Enter Invoice Title';
}
return $title;
}
add_filter( 'enter_title_here', 'change_default_title' );
@rsharrer
rsharrer / Login with username or email address.php
Created September 26, 2013 13:52
Login with username or email address
function login_with_email_address($username) {
$user = get_user_by('email',$username);
if(!empty($user->user_login))
$username = $user->user_login;
return $username;
}
add_action('wp_authenticate','login_with_email_address');
function change_username_wps_text($text){
if(in_array($GLOBALS['pagenow'], array('wp-login.php'))){
if ($text == 'Username'){$text = 'Username / Email';}
@rsharrer
rsharrer / Remove unset URL field from comment form.php
Created September 26, 2013 13:52
Remove / unset URL field from comment form
//remove or unset URL in comment
add_filter('comment_form_default_fields', 'unset_url_field');
function unset_url_field($fields){
if(isset($fields['url']))
unset($fields['url']);
return $fields;
}
@rsharrer
rsharrer / Force specific pages to be secure, ssl, https.php
Created September 26, 2013 13:48
Force specific pages to be secure, ssl, https
//Force Pages to SSL
function wps_force_ssl( $force_ssl, $post_id = 0, $url = '' ) {
if ( $post_id == 25 ) {
return true
}
return $force_ssl;
}
add_filter('force_ssl' , 'wps_force_ssl', 10, 3);
@rsharrer
rsharrer / new_gist_file
Created September 26, 2013 13:48
Ace Doran Functions
<?php
// Add Builder 3.0 Support
add_theme_support( 'builder-3.0' );
// Making all module outer wrappers full width
function it_set_full_width_container( $width ) {
remove_filter( 'builder_get_container_width', 'it_set_full_width_container' );
return '';
@rsharrer
rsharrer / displays search box.php
Created September 26, 2013 13:47
displays search box
<?php get_search_form(); ?>
@rsharrer
rsharrer / Changing the WordPress Read More Text.php
Created September 26, 2013 13:46
Changing the WordPress Read More Text
$custom_morelink = "Continue Reading the Full Article";
function change_more_link($more_link, $more_link_text) {
return str_replace($more_link_text, $custom_morelink, $more_link);
}
add_filter('the_content_more_link', 'change_more_link', 10, 2);
@rsharrer
rsharrer / Set Maximum Post Title Length.php
Created September 26, 2013 13:45
Set Maximum Post Title Length
//set post title length
function maxTitleLength($title) {
global $post;
$title = $post->post_title;
if (str_word_count($title) >= 10)
wp_die( __('Error: your post title is over the maximum word count.'));
}
add_action('publish_post','maxTitleLength');