Always keep a parameter in URL?

Is there any way that WordPress always keeps a custom parameter in every link it generates? Here’s what I want to do.

I want to create a debug mode by entering ?debug as a URL parameter; and display some specific information or do some debug only coding if that URL parameter is available. I know what I need to get WP to work with custom URL parameters. I want to know how can I make WP to keep debug parameter in all the liks it generates; and this parameter keeps propagating to all the links I click on while navigating the entire site until I remove it.

Related posts

1 comment

  1. You should not change the output you want to debug just to debug it, that’s a contradiction. 🙂

    Use cookies for that. For example, put something like this into your wp-config.php:

    if ( ! empty ( $_GET['debug'] ) )
    {
        if ( 'on' === $_GET['debug'] )
            set_debug_mode( TRUE );
        elseif ( 'off' === $_GET['debug'] )
            set_debug_mode( FALSE );
    }
    elseif ( isset ( $_COOKIE['debug'] ) )
    {
        if ( 'on' === $_COOKIE['debug'] )
            set_debug_mode( TRUE );
        else
            set_debug_mode( FALSE );
    }
    else
    {
        set_debug_mode( FALSE );
    }
    
    /**
     * Turn debug mode on or off.
     *
     * @param  bool $on
     * @return bool TRUE if cookie could be set.
     */
    function set_debug_mode( $on = TRUE )
    {
        if ( ! $on )
            return setcookie( 'debug', 'on', time() - 3600, '/' );
    
        define( 'WP_DEBUG',         TRUE );
        define( 'WP_DEBUG_DISPLAY', TRUE );
        define( 'SAVEQUERIES',      TRUE );
        define( 'DIEONDBERROR',     TRUE );
        define( 'SCRIPT_DEBUG',     TRUE );
    
        return setcookie( 'debug', 'on', time() + 604800, '/' ); // one week;
    }
    

    Now add ?debug=on to any URL, and all following requests will use the debug mode. Add ?debug=off to delete the cookie and to turn debug mode off.

Comments are closed.