Skip to content

Instantly share code, notes, and snippets.

View Tsunamijaan's full-sized avatar

Tariqul Islam Tsunamijaan

  • Coder Team IT
  • Rajshahi, Bangladesh
View GitHub Profile
@Tsunamijaan
Tsunamijaan / To Email User login support besides username
Created January 5, 2019 09:14
To Email User login support besides username
function dr_email_login_authenticate( $user, $username, $password ) {
if ( is_a( $user, 'WP_User' ) )
return $user;
if ( !empty( $username ) ) {
$username = str_replace( '&', '&', stripslashes( $username ) );
$user = get_user_by( 'email', $username );
if ( isset( $user, $user->user_login, $user->user_status ) && 0 == (int) $user->user_status )
$username = $user->user_login;
}
@Tsunamijaan
Tsunamijaan / Get top commenter author
Created January 5, 2019 09:13
Get top commenter author
function top_comment_authors($amount = 5){
global $wpdb;
$results = $wpdb->get_results('
SELECT
COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url
FROM
'.$wpdb->comments.'
WHERE
comment_author_email != "" AND comment_type = "" AND comment_approved = 1
GROUP BY
@Tsunamijaan
Tsunamijaan / Dynamic page content – page.php
Created January 5, 2019 09:12
Dynamic page content – page.php
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; endif; ?>
@Tsunamijaan
Tsunamijaan / Exclude Some Category from WP blog
Created January 5, 2019 09:11
Exclude Some Category from WP blog
function exclude_category($query) {
if ( $query->is_home() ) {
$query->set('cat', '-xx');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');
Or add below line before start loop have_posts() ) : while ( have_posts()=============
@Tsunamijaan
Tsunamijaan / After Content – More From This Category
Created January 5, 2019 09:10
After Content – More From This Category
<?php
function jeba_more_from_cat( $title = "More From This Category:" ) {
global $post;
// We should get the first category of the post
$categories = get_the_category( $post->ID );
$first_cat = $categories[0]->cat_ID;
// Let's start the $output by displaying the title and opening the <ul>
$output = '<div id="more-from-cat"><h3>' . $title . '</h3>';
// The arguments of the post list!
$args = array(
@Tsunamijaan
Tsunamijaan / To change the title attribute of WordPress login logo
Created January 5, 2019 09:10
To change the title attribute of WordPress login logo
@Tsunamijaan
Tsunamijaan / To remove login shake effect when error occurs on wp login
Created January 5, 2019 09:09
To remove login shake effect when error occurs on wp login
function wps_login_error() {
remove_action('login_head', 'wp_shake_js', 12);
}
add_action('login_head', 'wps_login_error');
@Tsunamijaan
Tsunamijaan / To use the WordPress limit excerpt
Created January 5, 2019 09:09
To use the WordPress limit excerpt
function new_excerpt_more( $more )
{
return ' Load More';
}
function custom_excerpt_length( $length )
{
return 500;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 500);
add_filter('excerpt_more', 'new_excerpt_more');
@Tsunamijaan
Tsunamijaan / To change any wp core file
Created January 5, 2019 09:08
To change any wp core file
// Custom login
function custom_login() {
$files = '<link rel="stylesheet" href="'.get_bloginfo('template_directory').'/css/login.css" />';
echo $files;
}
add_action('login_head', 'custom_login');
Or=======
@Tsunamijaan
Tsunamijaan / To add read more link after post excerpt
Created January 5, 2019 09:08
To add read more link after post excerpt
add_filter( 'excerpt_more', 'excerpt_more_example' );
function excerpt_more_example( $text ) {
global $post;
return '... <a class="read-more-link" href="' . get_permalink( $post->ID ) . '">Read more</a>';
}