Passing Extra Variables in URLs with WordPress
WordPress allows for the passing of extra variables in URLs, providing a convenient way to store and access information. However, adding extra variables to URLs can sometimes encounter difficulties.
Original Issue:
As highlighted in the inquiry, a user faced the challenge of passing an extra variable named 'c' in the URL of a WordPress installation. This variable was recognized at the website root (www.example.com?c=123) but failed to work in URLs containing additional information (www.example.com/news?c=123).
Solution:
The suggested solution involves utilizing the following three WordPress functions:
Implementation:
On the Page Creating the Link/Query Variable:
In functions.php or a Plugin File (Front-End Only):
On the Page Retrieving and Utilizing the Query Variable:
Additional Considerations for the Back End (wp-admin):
As the WP Query is not employed in wp-admin, the recommended approach is to examine the $_GET superglobal using filter_input() or the traditional isset() method.
Conclusion:
By implementing the functions and filter described above, you can effectively pass extra variables in URLs within your WordPress installation. This allows for greater flexibility in storing and accessing information, enhancing the functionality and user experience of your website.
The above is the detailed content of How to Pass Extra Variables in URLs with WordPress?. For more information, please follow other related articles on the PHP Chinese website!