CodeHub

Default comments SCSS | WordPress

/* =========================================================
Comments
========================================================= */
.comments-area {
	padding: 20px 40px;
	 textarea#comment {
	    width: 100%;
    }
	#submit {
		@extend .button;
	}
	 ol.commentlist {
	
	     list-style:none; 
	     margin:0 0 1em; 
	     padding:0; 
	     text-indent:0;
	    
	
	 	li {}
	 	li.alt {}
		li.bypostauthor {}
		li.byuser {}
		li.comment-author-admin {}
	
	
		.comment-body {
			border-bottom: 1px solid #ddd; 
			padding:1em;
	
			.comment-author {} // end .comment-author
	
			
			div.vcard {
	
				font-weight: 14px;
				
				cite.fn {
					a.url {}
				 } // end cite.fn
	
				 img.avatar {
				 	border:5px solid #ccc; 
				 	float:right; 
				 	margin:0 0 20px 20px;
				 } // end .avatar
	
				 img.avatar-32 {} // end .avatar-32
				 img.photo {} // end .photo
				 span.says {} // ebd .says
	
			}  // end .vcard
	
			div.commentmetadata {} // end .commentmetadata
			div.comment-meta {
	
				font-size: 11px;
	
					a {
						color: #ccc;
					} // end a
	
			} // end div.comment-meta
	
			p {font-size: 12px;} // end p
	
			ul {
				font-size: 12px;
				list-style: none;
				margin: 0 0 0 20px;
			} // end ul
	
			div.reply {
	
				font-size: 11px;
	
				a {font-weight: bold;} // end a
	
			} // end reply
	
			 ul.children {
				list-style:none; 
				margin: 12px; 
				text-indent:0;
	
				li {} // end li
	
				li.alt {} 
				li.bypostauthor {}
				li.byuser {}
				li.comment {}
				li.comment-author-admin {}
	
				li.depth-2 { border-left: 5px solid #ccc; margin:0 0 10px 10px; }
				li.depth-3 { border-left: 5px solid #bbb; margin:0 0 10px 10px; }
				li.depth-4 { border-left: 5px solid #aaa; margin:0 0 10px 10px; }
				li.depth-5 {} // you get the idea
	
				li.odd {} // end .odd
	
			}  // end ul.children
	
		}  // end li.comment
	
		li.even {background:#fff;}
		li.odd {background:#f6f6f6;}
		li.parent {border-left:5px solid #ddd;}
		li.thread-alt {}
		li.thread-even {}
		li.thread-odd {}
	
	 } // end commentlist
}

jQuery in the footer

Add this to your functions.php

function my_init()   
{  
    if (!is_admin())   
    {  
        wp_deregister_script('jquery');  
  
        // Load a copy of jQuery from the Google API CDN  
        // The last parameter set to TRUE states that it should be loaded  
        // in the footer.  
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js', FALSE, '1.11.0', TRUE);  
  
        wp_enqueue_script('jquery');  
    }  
}  
add_action('init', 'my_init');  

Remove script and style version numbers | WordPress

Add this to functions.php

// Pick out the version number from scripts and styles
function remove_version_from_style_js( $src ) {
    if ( strpos( $src, 'ver=' . get_bloginfo( 'version' ) ) )
        $src = remove_query_arg( 'ver', $src );
    return $src;
}
add_filter( 'style_loader_src', 'remove_version_from_style_js');
add_filter( 'script_loader_src', 'remove_version_from_style_js');

Echo thumbnail URL and size | WordPress

Use the PHP in the query below – and then the HTML example below to echo the URL out.

$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];
<div style="background: url(<?php echo($thumb_url) ?>);"></div>

Remove emoji code in header | WordPress

Add to functions.php

// REMOVE WP EMOJI
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');

remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

Change ellipses on excerpt | WordPress

Add to functions.php file.

function ld_new_excerpt_more($more) {
    global $post;
    return '...';
}
add_filter('excerpt_more', 'ld_new_excerpt_more');

Custom search form for WordPress

Create a file named searchform.php and place this in the root of the theme folder. This will replace the default WordPress search form.

<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
    <input type="text" placeholder="<?php echo esc_attr_x( 'Search website...', 'placeholder' ) ?>"
            value="<?php echo get_search_query() ?>" name="s"
            title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>"/>
</form>

Exclude current post from WordPress query

Get the current page ID and use that in the WordPress query to exclude that post from displaying.

<?php $currentID = get_the_ID();?>

<?php $args = array(
	'post_type' => 'post',
	'post__not_in' => array($currentID)
);

$query = new WP_Query($args);

 $i = 1;

while ( $query->have_posts() ) : $query-> the_post(); ?>

Registration white list | WordPress

Add this code in to your functions.php to create a domain whitelist for user registrations.

add_action('registration_errors', 'sizeable_restrict_domains', 10, 3);
function sizeable_restrict_domains( $errors, $login, $email ) {
	$whitelist = array(
        'domain.com', 
        'website.com'
    );
	if ( is_email($email) ) {
		$parts = explode('@', $email);
		$domain = $parts[count($parts)-1];
		$to = 'your@adminemail.com';
		$subject = 'Subject of email';
		$message = 'A user tried to register with the following email address: ' . $email;
		if ( !in_array(strtolower($domain), $whitelist) ) {
			$errors->add('email_domain', __('ERROR: You may only register with an approved email address.'));
		wp_mail( $to, $subject, $message );
		}
	}
	return $errors;
}