Not directly. Anything in the Editor is interpreted literally – you don’t use variables there.
It sounds like you’re using the Classic Editor – not blocks. If that’s the case, you could create a simple plugin that sets up a shortcode. That way, you can put the shortcode in the Editor, and it will run code that can then grab the current URL and put it in the link.
- Create a folder inside
/wp-content/plugins/– i.e./wp-content/plugins/shortcode-link/ - Create a file in the new folder – i.e.
/wp-content/plugins/shortcode-link/shortcode-link.php - The new file will define the plugin and then the shortcode:
<?php
/**
* Plugin Name: Shortcode Link
* Version: 1.0.0
*/
// Exit if accessed directly.
if ( !defined( 'ABSPATH' ) ) {
exit;
}
// Create a shortcode.
add_shortcode( 'shortcode_link', 'shortcode_link' );
/**
* Define what the shortcode does.
*
* @return string The output of the shortcode.
*/
function shortcode_link() {
// Get the current URL.
global $wp;
$current_url = home_url( $wp->request );
// Update this to whatever HTML output you want to display.
// This example is a link tag with a CSS "button" class, but
// you can make it anything you need.
return '<a class="button" href="https://example.com/patreon-flow/?patreon-login=yes&patreon-final-redirect=" . esc_url( $current_url ) . "">Support us on Patreon</a>';
}
(Now activate the plugin, and you can paste [shortcode_link] in the Editor and it’ll automatically output the code you set up. If you ever change that code it’ll auto-update across every page you’ve already added it.)
If you’re using blocks instead, you can use shortcodes, but it’s even better to create a custom block that does the same thing. You’d probably want a ServerSideRender which would make it easy to grab the current URL in PHP, just like you would do with the shortcode, except then it’d appear in a block instead of just the shortcode which doesn’t display its final output in the Editor.