In your plugin:
<?php
register_activation_hook(WP_PLUGIN_DIR.'/your/plugin/path/plugin.php', 'wpse_set_subdomain');
function wpse_set_subdomain() {
$siteurl = site_url();
$subdomain = substr($siteurl, 8, 3); // may need to adjust which substring to grab
update_option('wpse_subdomain', $subdomain);
}
?>
Then wherever you have conditional content:
<?php
$subdomain = get_option('wpse_subdomain');
if($subdomain == 'www') {
// www code
} else {
// other code
}
?>
As mentioned in the code comment, you may need to tweak which substring to grab by changing the numbers 8 and 3 (they’ll grab the first 3 letters starting at character 8 in the siteurl).
Related Posts:
- Security and .htaccess
- How to stop wordpress from changing default .htaccess permissions to 444
- What does a security risk in a plugin look like?
- Add .html extension to custom post type taxonomies
- Leverage browser caching not working after updating .htaccess
- How to install WordPress Multisite with different domains under the same subdirectory?
- 403 Forbidden – You don’t have permission to access /wp-admin/admin-ajax.php on this server
- Error Message from W3 Total Cache when .htaccess Rules Cannot Be Modified? [closed]
- htaccess and wordpress config files are regularly over written
- WordPress redirect all 404 pages to the Homepage
- How can I serve a text file at a custom URL
- 500 Internal Server Error when updating htaccess
- Write to / remove from default .htaccess file from plugin?
- Changed permalink structure. Need help with redirecting old posts
- Landing Page Redirect Chain | http->https->https www
- Possible htaccess configuration issue for HTTPS websites by WP Fastest Cache plugin? [closed]
- Headers Content-Security-Policy CSP Major Issue
- Create a multisite network for an existing installation
- admin-ajax.php warning max input vars exceeded on layered pop plugins [closed]
- Reoccurring 404 Errors on all subpages
- Is there a directory my plugin can write files to that cannot be viewed via the browser/url?
- plugin links not working [closed]
- Redirect to another page using contact form 7? [closed]
- Remove .htaccess portion upon plugin deactivation?
- Edit Permalink Structure For Custom Post Type or Modify .htaccess?
- Custom url rewriting
- WordPress rewrite rules not working
- Do rewrites added with add_rewrite_rule() persist after plugin deletion?
- can’t install any wp plugins [duplicate]
- Add a parameter at the end of the url and prettify
- www redirects to another directory in wordpress
- How to allow URL with filename & extension in wordpress?
- How To Use htaccess to Rewrite Link Structure for a Page that is Generated Programatcially
- WP Migrate DB Pro plugin cannot transfer Media files to remote server
- URL Rewrite 404
- .htaccess file doesn’t work, with hundred tries
- htaccess question and plugins.php
- Help Code Review – I need to write on .htaccess file from theme’s function.php
- Site not displaying correctly when re-directing from root to sub-directory
- How To Rewrite WordPress Pages URL Only?
- Apache rewrite rules and wordpress problem
- incorrect path of plugin dir on network
- My WP site and password was hacked, what to do? [closed]
- Please Check this ‘.htaccess’ File
- Allow direct access to files/folders within WordPress to replace wp-admin
- How to rewrite URL using .htaccess in WordPress Plugin
- Rewrite Rule in htaccess convert query string into slashes
- Twillio How To Send SMS for Custom Post Type
- Upgrading WordPress 4.0 asks for FTP password
- Change the name of an installed plugin
- Is there a way to lock certain pages from being edited by anyone other then the admin?
- WordPress ajax call for not logged in users, doesn’t work
- why in my wordpress admin panel the membership option is not showing
- Add multiple attributes to product from php
- What Plugin Do You Use to Turn WordPress based site to A Blog Aggregator
- like to keep reading plugin
- Check if email address exists front end with AJAX in a plugin
- How to review WordPress website php version compatibility?
- Translate database content using __($message) function
- Add Extra codes by plugin
- Edit default comments page in WP Admin
- Does WordPress validate inputs to all functions? (such as get_user_meta and insert_user_meta)
- Admin Theme customization
- wordpress json api not working
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- Problem with PHP wordpress, Undefined index: in C:\xampp\htdocs\wordpress\wp-content\plugins\epoch\classes\core.php on line 190 [closed]
- Contributive page where people logged in can write
- Contact Form 7 Get Image Function [closed]
- Implementing an image hosting website using WordPress? [closed]
- WP-DownloadManager – Query most download per week/month etc
- Displayed content disappears when adding attributes to shortcode
- Thesis 2 custom Page
- What is the easiest way to rename a plugin (and also avoid plugin updates)
- Display linked articles at the bottom of post (like related posts)
- register_activation_hook() not working as expected
- Plugin not working & permalink erorr after upgrade to php 7x on Nginx
- how to replace hostnames on certain external links?
- How to completely hide a WordPress/BuddyPress Install? [closed]
- Creating teams of users in WordPress
- Removing the custom_image_header from wp_head
- Is it safe to use Web Invoice 2.1.0 without SSL?
- How to properly replace the_content with the html in a php file?
- Is there a way to make [Table Of Content] plugin while not using revision data?
- Displaying all the images from all of my articles
- Problem with Date translation in WordPress
- install / update plugins remotely
- Why is my site still showing insecure icon even if I have SSL certificate?
- Forum creation with bbpress and front end
- Redirect login url
- Automatization for automatization
- Form submit from wordpress plugin
- WordPress Overrides folder permissions in Cpanel
- disable lightbox in a plugin [closed]
- Encode URL picked up by Digg Digg
- Share Bar over laps left column [closed]
- Frontpage Admin Bar Disappeared
- Need help saving input fields for Security Deposit plugin in WC Vendors page
- Count div with class (.length) only shows 0 [closed]
- Creating a Table Row by Row
- Getting 504 Gateway Timeout Error on AWS Server! [closed]