Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Forked from rafaehlers/gv-change-back-link.php
Last active January 4, 2022 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackkatz/c71ef120e13dfb9ea7432a24f46df9f9 to your computer and use it in GitHub Desktop.
Save zackkatz/c71ef120e13dfb9ea7432a24f46df9f9 to your computer and use it in GitHub Desktop.
GravityView - Change the back link URL for a specific View ID
@kalamalahala
Copy link

kalamalahala commented Jan 4, 2022

Thanks!

I used this to maintain parameters being passed to the Multiple Entries page which filters table contents.

function gv_change_back_link( $href = '', $context = null ) {
    
    // GitHub snippet to get full URI, parameters, and anchor
    $base_url = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' ? 'https' : 'http' ) . '://' .  $_SERVER['HTTP_HOST'];
    $url = $base_url . $_SERVER["REQUEST_URI"];

    // parse_url with PHP_URL_QUERY to return all parameters as a string, append them to a question mark
    $parameters = '?' . parse_url($url, PHP_URL_QUERY);

	if( 7126 === $context->view->ID ) {
        // Use original Go Back link with appended parameters
		return $href . $parameters;
	}
	
	return $href;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment