Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8102279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:12:15+00:00 2026-06-05T23:12:15+00:00

I need to construct a link in WordPress based on a variable out of

  • 0

I need to construct a link in WordPress based on a variable out of the URL of that page.
Although in PHP this might be easy, in WP this seems to be difficult (I understood that WP does not allow it for security reasons).
So, I added a filter in my WordPress installation (functions.php) according to this link in order to get that variable and use it programatically in my WP post page in the construction of my link.
However, the link forms with two spaces (one before and one after I call the relevant function).

So, the code behind the link is:

<?php echo ("<a href='www.mydomain.com/purchases/?refid="); ?> <?php echorefid(); ?> <?php echo ("'>download this amazing file</a>") ?>

and the output code (in HTML) when I try to access the webpage at http://www.mydomain.com/?refid=3267 is:

<a href='www.mydomain.com/purchases/?refid= 3267 '>download this amazing file</a>

Please note the space before 3267 string and the space after this string.
Obviously, the link is broken.

The function echorefid() appears in the following code I added to functions.php:

add_filter('query_vars', 'parameter_queryvars' );

function parameter_queryvars( $qvars ) 
{ 
$qvars[] = 'refid'; 
return $qvars; 
} 

function echorefid() 
{ 
global $wp_query; 
if (isset($wp_query->query_vars['refid'])) 
{ 
print $wp_query->query_vars['refid']; 
} 
}    

Any help would be highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:12:17+00:00Added an answer on June 5, 2026 at 11:12 pm

    The cause of the spaces it the fact that you have separated multiple <?php ?> <?php ?> with spaces separating them. Those spaces outside <?php ?> tags are sent as output to the browser.

    You only need one of them for all the PHP code. Combine them by concatenating the three groups and switch the outer quotes to single quotes or escape the inner quotes.

    <?php echo '<a href="www.mydomain.com/purchases/?refid=' . echorefid() . '">download this amazing file</a>'; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to construct the URL of a page in a String, to send
So we have the menu above. That I need to construct for a WordPress
Given an absolute url of a page, and a relative link found within that
I need to be able to construct a link in the Action on the
This has been driving me crazy. I need to construct a single regex expression
I need to construct a long string with javascript. Thats how i tried to
I need to construct an if statement from the data coming from the client
I need to construct a file path inside a java program. Which path separator
I need to construct directed graph (at runtime) with cycles in Prolog and I
Currently i need to construct and update large xml files. So what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.