Skip to content

Instantly share code, notes, and snippets.

<?php
function add_csutom_code_on_entire_network(){?>
<style type="text/css">
/*Your custom CSS code will go here*/
</style>
<?php }
add_action('wp_footer','add_csutom_code_on_entire_network', 999);
@sjaved87
sjaved87 / modify_search_query.php
Created June 19, 2016 13:19
Include only specific post types in search results. The following will only include post and product post types in search results. Feel free to add remove your own post type names (coma separeated)
<?php
function SearchFilter( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', array( 'post', 'product' ) );
}
}
return $query;
@sjaved87
sjaved87 / redirect_from_signup_to_custom_page.php
Created June 17, 2016 11:46
This code snippet will redirect user from wp-signup.php on multisite to a custom page URL. Don't forget to replace Your_URL_GOES_HERE with actual target page URL.
<?php
function sjaved_redirect_user_from_wp_signup(){
global $pagenow;
if( $pagenow == 'wp-signup.php'){
wp_redirect( 'Your_URL_GOES_HERE' );
exit;
}
}
@sjaved87
sjaved87 / text-change.php
Created June 7, 2016 21:35
Use below code to change the text on anywhere (restrict it with text domain name) on your WordPress Single Site or Multisite.
<?php
add_filter('gettext', 'sjaved_change_text_dynamically', 99, 3);
if(function_exists('sjaved_change_text_dynamically')) :
function sjaved_change_text_dynamically( $translated_text, $untranslated_text, $domain ){
if($domain == 'YourTextDomain' and $untranslated_text == 'YourText' ){
$translated_text = 'ReplacedText';
@sjaved87
sjaved87 / remove_admin_ads.php
Created May 27, 2016 14:12
[Admin Ads] This will restrict admin ads to show on dashbaord page of network only.
<?php
add_action('admin_init', 'remove_admin_ads_from_other_pages');
function remove_admin_ads_from_other_pages(){
global $pagenow;
if($pagenow != 'index.php')
remove_action('admin_notices', 'admin_ads_output');
}
@sjaved87
sjaved87 / open_external_links_in_new_window.php
Last active May 14, 2016 17:40
WordPress open all external links in new window.
@sjaved87
sjaved87 / noymmedia.php
Created March 27, 2016 12:35
This small snippet will disable the use of year month format to store media on signup.
<?php
function wpmudev_set_default_media_settings( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
update_blog_option( $blog_id, $option = 'uploads_use_yearmonth_folders', $value = 0, $deprecated );
}
add_action( 'wpmu_new_blog', 'wpmudev_set_default_media_settings',10, 6 );
@sjaved87
sjaved87 / rups_on_login.php
Created March 24, 2016 14:37
This code snippet will detect the user's site automatically on login and redirect to respective site after login. For WordPress MultiSite only.
<?php
function go_to_primary_blog($redirect_to, $request, $user){
$user_info = get_userdata($user->ID);
return get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin';
}
add_filter("login_redirect", "go_to_primary_blog", 999, 3);
@sjaved87
sjaved87 / remove_query_strings_from_mp3_url.php
Created March 23, 2016 12:56
In rare case, if you want to remove the query string added by WordPress at the end of mp3 files. You can use this snippet.
<?php
if( !function_exists('wpmudev_remove_query_string_from_mp_url') ) :
add_filter('wp_audio_shortcode', 'wpmudev_remove_query_string_from_mp_url', 10, 5);
function wpmudev_remove_query_string_from_mp_url( $html, $atts, $audio, $post_id, $library ){
$post_id = get_post() ? get_the_ID() : 0;
static $instance = 0;
@sjaved87
sjaved87 / remove_duplicate_password_fields.php
Last active March 20, 2016 09:52
This snippet will remove duplicate password fields on custom registration pages added by "Set Password on Multisite Blog Creation" plugin.
<?php
if( !function_exists('wpmudev_remove_set_pass_on_custom_registration_pages') ) :
add_action('init', 'wpmudev_remove_set_pass_on_custom_registration_pages', 10);
function wpmudev_remove_set_pass_on_custom_registration_pages( $col_headers ){
global $pagenow;
if( $pagenow != 'wp-signup.php' && ( !isset( $_GET['action'] ) && $_GET['action'] != 'new_blog' ) ){
//Remove all actions of set password on multisite blog creation plugin if we are not on default signup page or on prosites add new blog page.