Skip to content

Instantly share code, notes, and snippets.

@tahirtaous
tahirtaous / unregister-sidebar
Created January 8, 2015 20:36
WordPress : Unregistering Parent Theme Sidebar in Child Theme
// Remove 2012 default sidebar widgets from admin area
// http://codex.wordpress.org/Function_Reference/unregister_sidebar
// following code will remove/unregister 2012 sidebars from admin area
// you can unregister any sidebar just replave sidebar-1 sidebar-2 and sidebar-3 with your sidebar id. you can find sidebar id's
// in parent theme's functions.php file
// http://codex.wordpress.org/Function_Reference/unregister_sidebar for more details
function remove_some_widgets(){
// Unregister some of the TwentyTen sidebars
unregister_sidebar( 'sidebar-1' );
@tahirtaous
tahirtaous / Se hidden WordPress database settings
Last active August 29, 2015 14:13
See all database related WordPress setting
// CUSTOM ADMIN MENU LINK FOR ALL SETTINGS Under Setting Menu
function all_settings_link() {
add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
}
add_action('admin_menu', 'all_settings_link');
@tahirtaous
tahirtaous / NextPrevious Pages function NOT posts
Last active August 29, 2015 14:13
WordPress Next & Prevous Page not Post with Bootstrap pager styling
<!-- add this code in page.php to display Next page and Previous page link below pages in WordPress
this will display next and previous page link not next previous post link
http://codex.wordpress.org/Next_and_Previous_Links#The_Next_and_Previous_Pages -->
<?php
$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
$pages = array();
foreach ($pagelist as $page) {
$pages[] += $page->ID;
}
@tahirtaous
tahirtaous / Delete PostRevisions Without Plugin
Last active August 29, 2015 14:13
Delete WordPress post revisions without plug in with this Native function
// Open you functions.php file and paste the following code:
// Save the file and open your blog homepage to run the code. Once done, there’s no need to keep the code snippet in your
// functions.php file, as it will always delete all post revisions. So simply remove it.
// http://www.wprecipes.com/easily-delete-wordpress-post-revisions-using-your-fuctions-php-file
$wpdb->query( "
DELETE FROM $wpdb->posts
WHERE post_type = 'revision'
" );
@tahirtaous
tahirtaous / function to Unregister WP Default Widgets
Created January 11, 2015 19:18
WordPress has many default widgets such as recent post, calendar, meta, pages, rss and others, you can delete all widgets with this function. Add this to your functions.php file
// Source : http://wordpress.stackexchange.com/questions/1567/best-collection-of-code-for-your-functions-php-file
// unregister all default WP Widgets
function unregister_default_wp_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Text');
@tahirtaous
tahirtaous / Add contact details to WordPress dashnoard for clients
Last active August 29, 2015 14:13
You can use this for client sites as a simple point of reference to contact you as the developer
// Wordpress Custom Admin Footer
// customize admin footer text. Add this to functions.php
// Source http://wordpress.stackexchange.com/posts/6005/revisions
// Modified by Tahir Taous
// customize admin footer text Will be visible in Dashboard
function custom_admin_footer() {
echo 'Created By <a href="//tahirtaous.com/contact">Tahir Taous</a> ';
}
@tahirtaous
tahirtaous / Remove version string, error messages for better WordPress Security
Last active August 29, 2015 14:13
Security through obscurity is the name of the game here. These functions do three different things. Remove the version string from the code. No point in telling folks what version we're running. Removes any error messages (Wrong Password, No Such User, etc.) from admin login screens When the admin posts a comment, a CSS class is added. This remo…
// Source http://wordpress.stackexchange.com/posts/28530/revisions
// Tested and worked on WordPress 4.1 Beta
//REMOVE VERSION STRING FROM HEADER
remove_action('wp_head', 'wp_generator');
//HIDE LOGIN ERROR MESSAGES (Wrong Password, No Such User etc.)
add_filter('login_errors',create_function('$a', "return null;"));
// Remove admin name in comments class
// Source: http://www.wprecipes.com/wordpress-hack-remove-admin-name-in-comments-class
@tahirtaous
tahirtaous / WordPress antispam email functions
Last active August 29, 2015 14:14
This is probably one of the most well-hidden functions in the WordPress codebase. This function aims to convert an email into HTML entities in order to mask email addresses from evil scrapers.
// Reference : https://www.cms2cms.com/blog/6-useful-yet-relatively-unknown-wordpress-functions/
// add this code to sidebar.php or anywhere you want to display email addess
// remove <?php and ?> if you are going to paste this in functions.php
// Tested WordPress 4.1 Jan 25 2015
<?php
$email = 'mymail@mail.com';
echo 'You can contact me at ' . antispambot( $email ) . ' any time';
@tahirtaous
tahirtaous / Last Modified Date or time WordPress
Created January 25, 2015 14:26
This function outputs the difference between two timestamps and is presented in a human readable format like “10 mins”, “1 hour”, “3 days”. It has some similarity with the popular Twitter “time ago” function, and is considered to be quite useful for displaying when the post was last modified.
// Source: https://www.cms2cms.com/blog/6-useful-yet-relatively-unknown-wordpress-functions/
// This function will generate something like this
// This post was published 2 weeks ago
// Tested : WordPress 4.1
<?php
echo 'This post was published ' . human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' ago';
?>
@tahirtaous
tahirtaous / WordPress functions only for mobile users
Created January 25, 2015 14:30
This is a little-known built-in function of WordPress that detects whether a user is visiting on a mobile device or not and allows to display content accordingly. It is quite handy function for those willing to include a bit of code for only mobile users.//
// This code will show message only on mobile devices
// only mobile users will see this message
// Source: https://www.cms2cms.com/blog/6-useful-yet-relatively-unknown-wordpress-functions/
// Tested: WordPress 4.1 Jan 25 2015
<?php if( wp_is_mobile() ) : ?>
Visit our website on your desktop for a richer user experience
<?php endif ?>