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 / Add auto logout period
Created January 5, 2019 08:49
Add auto logout period
function logged_in( $expirein ) {
return 604800; // 1 week in seconds
}
add_filter( 'auth_cookie_expiration', 'logged_in' );
@Tsunamijaan
Tsunamijaan / Style the tag cloud
Created January 5, 2019 08:27
Style the tag cloud
add_filter('widget_tag_cloud_args','style_tags');
function style_tags($args) {
$args = array(
'largest' => '10',
'smallest' => '10',
'format' => 'list',
);
return $args;
}
@Tsunamijaan
Tsunamijaan / Add pagination by using function
Created January 5, 2019 08:26
Add pagination by using function
function my_paginate_links() {
global $wp_rewrite, $wp_query;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$pagination = array(
'base' => @add_query_arg('paged','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'prev_text' => __('« Previous'),
@Tsunamijaan
Tsunamijaan / Maintenance mode using function
Created January 5, 2019 08:26
Maintenance mode using function
function maintenace_mode() {
if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {wp_die('Maintenance.');}
}
add_action('get_header', 'maintenace_mode');
@Tsunamijaan
Tsunamijaan / To show post views
Created January 5, 2019 08:25
To show post views
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count.' Views';
}
@Tsunamijaan
Tsunamijaan / Disable widget areas on specific pages
Created January 5, 2019 08:24
Disable widget areas on specific pages
<?php
add_filter( 'sidebars_widgets', 'disable_sidebar_widgets' );
function disable_sidebar_widgets( $sidebars_widgets ) {
if ( is_page('about-me') )
$sidebars_widgets = array( false );
return $sidebars_widgets;
}
?>
@Tsunamijaan
Tsunamijaan / Automatically Link Twitter Usernames In Content
Created January 5, 2019 08:23
Automatically Link Twitter Usernames In Content
@Tsunamijaan
Tsunamijaan / Set Minimal Comment Limit
Created January 5, 2019 08:22
Set Minimal Comment Limit
add_filter( 'preprocess_comment', 'minimal_comment_length' );
function minimal_comment_length( $commentdata ) {
$minimalCommentLength = 20;
if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength )
{
wp_die( 'All comments must be at least ' . $minimalCommentLength . ' characters long.' );
}
return $commentdata;
@Tsunamijaan
Tsunamijaan / Restrict Admin Area To Only Admin Users
Created January 5, 2019 08:21
Restrict Admin Area To Only Admin Users
function restrict_admin()
{
if ( ! current_user_can( 'manage_options' ) ) {
wp_redirect( site_url() );
exit;
}
}
add_action( 'admin_init', 'restrict_admin', 1 );
@Tsunamijaan
Tsunamijaan / Disable Changing The WordPress Theme
Created January 5, 2019 08:20
Disable Changing The WordPress Theme
/**
* Disable changing the theme for anyone a part from the admin user
* Only can be changes
*/
add_action('admin_init', 'disable_changing_theme_for_non_admin');
function disable_changing_theme_for_non_admin() {
global $submenu, $userdata;
get_currentuserinfo();
if ($userdata->ID != 1) {