WordPress.org

Ready to get started?Download WordPress

Forums

JP Theme Switcher Bar
stay on same page when switch? (2 posts)

  1. cheekyboots
    Member
    Posted 4 months ago #

    Right now when you are on a subpage of the site, and click on a new theme, it takes you back to the homepage to show the new theme. Is there any way for it to leave you on the same page, just with the new theme?

    https://wordpress.org/plugins/jp-theme-bar/

  2. Josh Pollock
    Member
    Plugin Author

    Posted 4 months ago #

    Right now the link is constructed using site_url() plus the theme query var. See:

    https://github.com/Shelob9/jp-theme-bar/blob/master/jptb-frontend.php#L101

    and

    https://github.com/Shelob9/jp-theme-bar/blob/master/jptb-frontend.php#L127

    You could add a method to get the current url instead of site_url(), something like this:

    function current_page_url() {
    		$pageURL = 'http';
    		if( isset($_SERVER["HTTPS"]) ) {
    			if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    		}
    		$pageURL .= "://";
    		if ($_SERVER["SERVER_PORT"] != "80") {
    			$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    		} else {
    			$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    		}
    		return $pageURL;
    	}

    Here's the catch, if current URL already has a variable attached, then you need to append &theme= instead of ?theme= for obvious reasons. Not sure if that should be handled with conditionals or str_replace().

    If you get this working and submit a pull request (https://github.com/Shelob9/jp-theme-bar) I'd be grateful.

    Take care,
    Josh

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.