Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Shortcode to log user into current URL

I am not sure that you can put a function inside that statement (or that particular function).

But I would test the process by using this test code

$permalink = get_permalink();
$loginurl = wp_login_url($permalink); 
echo "permalink is $permalink<br>";
echo "loginurl is $loginurl <br>";

Turn on error logging/display to see any errors.

And all of this is assuming that you have loaded all of the WordPress stuff to use the WP functions. Your code by itself won’t run without the WP stuff…perhaps that is your problem.

Note that the get_permalink() function will return false if a post is not ‘active’…so you will need to put your test code inside a WP ‘loop’.

The wp_login_url returns the login URL of the WP site. It will be the same for any part/post of your site, so doesn’t depend on the permalink value.

Remember that the wp_login_terminal parameter is where the user will go when they login correctly. So the 2nd line of the code above should just be

$loginurl = wp_login_url();

Related Posts:

  1. Having trouble creating two shortcodes, one for logged in user and one for visitors
  2. How create a Shortcode with hover and complex options
  3. Remove   from shortcode
  4. Displaying recent posts on static page with template-part via shortcode
  5. wordpress 4.4 self hosted video (html5) doesn’t show
  6. do_shortcode with custom field
  7. How to Reference/Echo Variable from Another PHP Function
  8. Remove echo from shortcode
  9. Replace shortcode in substring
  10. Problem with login form
  11. Login to wordpress by clicking a link and specifying usernaname and password in url
  12. Shortcode to show the code
  13. Shortcode returns values in the wrong order
  14. Log in / Log Out Custom Button
  15. Get URL from shortcode tag
  16. Embedding PHP in shortcode $content
  17. Shortcode with PHP issue “Undefined index”
  18. Should `wp_login` be used since it’s deprecated?
  19. How to redirect users based on role and content of redirect_to?
  20. Excecuting php function in shortcode
  21. Only first shortcode gets executed
  22. Change CSS based on is_user_logged_in
  23. Multiple do_shortcode in page template
  24. How to display login form anywhere, when user isn’t logged in, without redirecting?
  25. How can I open up my administrative panel to everyone?
  26. Returning data instead of echoing/printing
  27. echo something inside a shortcode
  28. displaying content that includes shortcodes within an echo
  29. List taxonomy term slugs within shortcode (do_shortcode)
  30. Shortcode from a function not working
  31. Display Data in Table from External Database in WP using Shortcodes
  32. get_posts works in the page template but not in a shortcode
  33. Is it possible to return content, and then also continue to do other things?
  34. ::before on open/close function [closed]
  35. anyway to put inside a $outprint=sprintf()
  36. Is There A Way To Make Theme Files Accept Shortcodes?
  37. How can I include shortcodes within PHP?
  38. Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
  39. Create a WordPress shortcode using PHP [duplicate]
  40. do_action(), iFrame Gets Displayed Despite Password Protection [closed]
  41. $wpdb returns duplicate posts
  42. Creating WordPress Shortcode with Variable
  43. Catchable fatal error: Object of class stdClass could not be converted to string
  44. Syntax error in a shortcode function
  45. Using Shortcode to Grab Archive Listing, Separate by Year
  46. Capitalize Shortcode Value on Output
  47. Shortcode to find and replace URL
  48. Why is my str_replace not working on short code submitted by front-end?
  49. Could use some help with Shortcodes
  50. How to put a form with php code into a variable or shortcode?
  51. Unable to process php via shortcode
  52. Help with WordPress function inside a shortcode
  53. calling a custom field value inside functions.php
  54. Using ob_start and ob_get_clean with wordpress shortcode
  55. Short code template + ajax
  56. WordPress shortcode returns the data before
  57. List all blogs, but exclude the main site
  58. How can I add a new row in a separate database when someone registers via WordPress?
  59. Shortcode to embed Edit Account form not working
  60. Shortcode not staying inside div tag
  61. Line breaks inside shortcode variable
  62. Handling PHP/HTML inside the output of a shortcode function
  63. Shortcode for Listing Users from Meta Value?
  64. One account with multiple logins
  65. Cant display an image via PHP in wordpress
  66. Shortcode to pull posts
  67. Lost in trying to create user database system
  68. PHP code inside Shortcode
  69. Need to Modify a WordPress Shortcode with another wordpress shortcode
  70. Help Fallback (thumbnail)
  71. How to return a string that has a jQuery and Ajax inside in a shortcode?
  72. Shortcode function doesnt work without caption
  73. Action Hook Inside WordPress Plugin Shortcode
  74. How can I include the user id inside of a shortcode php output?
  75. Split shortcodes to array of shortcodes
  76. Shortcodes showing in excerpt despite using strip_shortcodes
  77. PHP error with a shortcode: “no suitable wrapper” for file_get_contents
  78. PHP Helper Class to create shortcodes
  79. Calling PHP Titles inside Javascript Markup
  80. PHP getting error when trying to access WP-Admin Dashboard
  81. I installed WordPress locally now how do I login?
  82. If user is logged in not working
  83. Change homepage content if user is logged in – BuddyPress
  84. How to make a conditional statement within $output in shortcodes.php?
  85. help with custom shortcode that stopped working
  86. Create special button on WP Tiny MCE Posts Editor for Shortcodes
  87. Change Spaces to Dashes?
  88. Shortcode for a Series of Elevating Image Files, Excluding a Range?
  89. Shortcode won’t execute
  90. How to get my [shortcode] rendered on the home page, other pages are fine
  91. Including Custom fields within the_content
  92. Show login greeting above sub-menu links?
  93. What is the difference between Null vs Empty (Zero Length) string?
  94. Shortcode displaying at the top of the page [duplicate]
  95. AJAX function not working [closed]
  96. is_user_logged_in returning nothing on custom page
  97. Can ‘Custom Field’ data be inserted into this Short Code?
  98. Help with accessing wp-admin page and resolving error messages
  99. MySQL Query Returns Array () In Shortcode
  100. how to get sentence values from wordpress shortcode parameter?
Categories PHP Tags login, php, shortcode
Is it possible to instantiate a new WC_Cart?
Shortcode function doesnt work without caption

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress