Pages

Thursday, January 30, 2014

How to change month format from archive widget? - [Resolved]


Please write below code in functions.php

add_filter('get_archives_link', 'translate_archive_month');

function translate_archive_month($list) {

     $patterns = array('/January/', '/February/', '/March/', '/April/', '/May/', '/June/', '/July/', '/August/', '/September/', '/October/',  '/November/', '/December/');

    $replacements = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');    

    $list = preg_replace($patterns, $replacements, $list);

    return $list; 

}

Friday, January 24, 2014

Repeater not saving on some pages, but works on others - [Solved]

If your ACF repeater fields are not updating after saving the post than please insert below code in ".htaccess" file. Which one is placed on your root directory.

php_value max_input_vars 10000
php_value memory_limit 500M
php_value max_execution_time 60
php_value post_max_size 500M

Monday, January 20, 2014

Remove default category slug from permalink - wordpress

Please write below code in functions.php

// Remove category base
add_action('init', 'no_category_base_permastruct');
function no_category_base_permastruct() {
global $wp_rewrite, $wp_version;
if (version_compare($wp_version, '3.4', '<')) {
$wp_rewrite -> extra_permastructs['category'][0] = '%category%';
} else {
$wp_rewrite -> extra_permastructs['category']['struct'] = '%category%';
}
}

// Add our custom category rewrite rules
add_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');
function no_category_base_rewrite_rules($category_rewrite) {

$category_rewrite = array();
$categories = get_categories(array('hide_empty' => false));
foreach ($categories as $category) {
$category_nicename = $category -> slug;
if ($category -> parent == $category -> cat_ID)// recursive recursion
$category -> parent = 0;
elseif ($category -> parent != 0)
$category_nicename = get_category_parents($category -> parent, false, '/', true) . $category_nicename;

$category_rewrite['(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]';
}
// Redirect support from Old Category Base
global $wp_rewrite;
$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
$old_category_base = trim($old_category_base, '/');
$category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]';

return $category_rewrite;
}

Thursday, January 9, 2014

Add or update user column in admin panel - wordpress

add_filter('manage_users_columns', 'drop_video_columns_head');
function drop_video_columns_head($defaults_columns) {
unset($defaults_columns['posts']);
unset($defaults_columns['name']);
$defaults_columns['uservideos']  = 'Videos';
return $defaults_columns;
}
add_filter('manage_users_custom_column', 'drop_video_columns_content_users', 10, 3);
function drop_video_columns_content_users($c, $column_name, $user_id){

if ($column_name == 'uservideos') {
global $wpdb;
        $num_videos = $wpdb->get_results("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'youtube' AND post_status = 'publish' and post_author = {$user_id} ",'ARRAY_A');
return $num_videos[0]['COUNT(*)'];
}
}

Monday, January 6, 2014

How to Disable the WordPress Update Notice?

If you want to disable update notification in wordpress than please write below code in functions.php

/*******************  Method 1  ***********************/
//Disable Theme Updates # 3.0+
remove_action( 'load-update-core.php', 'wp_update_themes' );
add_filter( 'pre_site_transient_update_themes', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_update_themes' );

//Disable Plugin Updates #3.0+
remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_update_plugins' );

//Diasable Core Updates # 3.0+
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
wp_clear_scheduled_hook( 'wp_version_check' );


/*******************  Method 2  ***********************/

function remove_core_updates(){

        global $wp_version;
        return (object) array(
            'last_checked' => time(),
            'version_checked' => $wp_version,
            );
}
add_filter('pre_site_transient_update_core', 'remove_core_updates');
add_filter('pre_site_transient_update_plugins', 'remove_core_updates');
add_filter('pre_site_transient_update_themes', 'remove_core_updates');

Friday, January 3, 2014

Get Page Id from Page Slug - Wordpress

If you want to get page id from page URL than you can use below function:

$postid = url_to_postid( $url );