Skip to content

Instantly share code, notes, and snippets.

View fahidjavid's full-sized avatar
🎯
Focusing

Fahid Javid fahidjavid

🎯
Focusing
View GitHub Profile
@fahidjavid
fahidjavid / query-taxonomy-page.php
Last active November 24, 2015 17:46
[WordPress] Modify the posts query on the taxonomy template.
<?php
global $wp_query;
query_posts(
array_merge(
array(
'order' => 'ASC',
'posts_per_page' => 8
),
$wp_query->query
@fahidjavid
fahidjavid / remove_filter.php
Created June 12, 2014 08:48
Disable Fancy Characters.
remove_filter ('the_content', 'wpautop');
remove_filter ('single_post_title', 'wptexturize');
remove_filter ('bloginfo', 'wptexturize');
remove_filter ('wp_title', 'wptexturize');
remove_filter ('category_description', 'wptexturize');
remove_filter ('list_cats', 'wptexturize');
remove_filter ('comment_author', 'wptexturize');
remove_filter ('comment_text', 'wptexturize');
remove_filter ('the_title', 'wptexturize');
@fahidjavid
fahidjavid / admin_bar_disable.php
Created June 12, 2014 08:50
Show The Admin Bar For Administrators Only
if (!current_user_can( 'manage_options' )) {
add_filter('show_admin_bar', '__return_false');
}
@fahidjavid
fahidjavid / own_admin_bar.php
Created June 12, 2014 08:51
Make Your Own Admin Bar.
<?php
function MyFirstAdminBar(){
//global variables
global $user_ID,$current_user,$user_identity;
//the following obtains all of the user's profile data
get_currentuserinfo();
//the following will execute if the user is logged in
@fahidjavid
fahidjavid / create-user-ftp.php
Last active August 29, 2015 14:02
Create WordPress Admin Account Using FTP/PHP
<?php
function admin_account(){
$user = 'AccountID';
$pass = 'AccountPassword';
$email = 'email@domain.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
@fahidjavid
fahidjavid / menus-to-locations.php
Created June 26, 2014 11:14
How to set WordPress Menus to Theme Locations
<?php
$locations = get_theme_mod( 'nav_menu_locations' ); // registered menu locations in theme
$menus = wp_get_nav_menus(); // registered menus
if($menus) {
foreach($menus as $menu) { // assign menus to theme locations
if( $menu->name == 'Main' ) {
$locations['main_navigation'] = $menu->term_id;
} else if( $menu->name == '404' ) {
@fahidjavid
fahidjavid / check-sessions.php
Created June 26, 2014 12:37
Check if Sessions are enabled and working.
<?php
$sessionfile = ini_get('session.save_path') . '/' . 'sess_'.session_id();
echo 'session file: ', $sessionfile, ' '.'';
echo 'size: ', filesize($sessionfile), "\n";
@fahidjavid
fahidjavid / schedule_event.php
Created August 25, 2014 07:33
To schedule an hourly event in a plugin, call wp_schedule_event on activation (otherwise you will end up with a lot of scheduled events!):
register_activation_hook( __FILE__, 'prefix_activation' );
/**
* On activation, set a time, frequency and name of an action hook to be scheduled.
*/
function prefix_activation() {
wp_schedule_event( time(), 'hourly', 'prefix_hourly_event_hook' );
}
add_action( 'prefix_hourly_event_hook', 'prefix_do_this_hourly' );
/**
@fahidjavid
fahidjavid / menu-waker.php
Created September 17, 2014 06:11
Editing the output by using a custom walker
class description_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
@fahidjavid
fahidjavid / hide-preview-view-permalink.txt
Last active February 26, 2020 11:18
Hide preview, view and permalink field for the posts and custom post types.