jordanmaslyn
5/19/2016 - 6:15 PM

Filter a Wordpress URL

Filter a Wordpress URL

function custom_site_url( $url ) {
    if( is_admin() ) {
      return $url;
    } // you probably don't want this in admin side

    $replaced = array("buzzed", "blogspot.");

    foreach ($replaced as $replace) {
      if (strpos( parse_url($url, PHP_URL_HOST), $replace ) !== false) {
        return str_replace($replaced, "", $url);
      }
    }

    return $url;
}

if (!is_admin() && !in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) {
  add_filter('bloginfo_url', 'custom_site_url');
  add_filter('theme_root_uri', 'custom_site_url');
  add_filter('stylesheet_directory_uri', 'custom_site_url');
  add_filter('template_directory_uri', 'custom_site_url');
  add_filter('script_loader_src', 'custom_site_url');
  add_filter('style_loader_src', 'custom_site_url');
  add_filter('plugins_url', 'custom_site_url');
  add_filter('the_permalink', 'custom_site_url');
  add_filter('wp_list_pages', 'custom_site_url');
  add_filter('wp_list_categories', 'custom_site_url');
  add_filter('wp_nav_menu', 'custom_site_url');
  add_filter('the_content_more_link', 'custom_site_url');
  add_filter('the_tags', 'custom_site_url');
  add_filter('get_pagenum_link', 'custom_site_url');
  add_filter('get_comment_link', 'custom_site_url');
  add_filter('month_link', 'custom_site_url');
  add_filter('day_link', 'custom_site_url');
  add_filter('year_link', 'custom_site_url');
  add_filter('tag_link', 'custom_site_url');
  add_filter('the_author_posts_link', 'custom_site_url');
}