Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-16235

URLs in WordPress based upon unrelated post/page


    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
    • Funding Source:
      Needs Funding


      When a post remains in "the loop" in WordPress, the CRM_Utils_System_WordPress::url() function decides to base all CiviCRM URLs off of it.

      It's clear that in many places, this is appropriate. For example, you may have a page at example.org/shindig for and info page for your fundraising shindig. It's a nice feature that the registration link ends up as
      instead of

      However, in other situations, this is inappropriate. The most glaring example is if you have a widget of recent posts on the sidebar. If you install CiviCRM in a clean copy of WordPress 4.1.1 with all of its defaults (but with the post title as the permalink), and you visit the public event listing page at
      you'll notice that the event URLs are all like
      Similarly, go to an event info page like
      and find that the registration button points to
      I imagine the same thing happens for PCPs.

      As best as I can tell, the issue is that the widget runs through The Loop, and when it's through, the $post object is still set to that post. CRM_Utils_System_WordPress::url() blindly gets its URL and makes that the base page for links:

      So, this has two consequences for site administrators. First, there's the simple SEO problem when you have multiple links to the same place. A site admin has no way to clean this up reliably, and it'll be a new URL every few days for the same event, since the URL will pick up the permalink of the recent post over on the side.

      The second issue is even bigger. If you have your theme setting layout, colors, and/or headings based upon the page, you won't want to have that change at random for events and personal campaign pages as people link from one CiviCRM page to the next. At least, the branding will be off. At worst, a weird page layout could discourage event registrations and PCP donors.

      I don't have a firm opinion on how to address this. I tried to check whether CiviCRM_For_WordPress::$context == 'shortcode', but that causes the follow-up steps of event registration to break, because their context is "basepage". I think the best plan would be yet another argument passed to CRM_Utils_System::url()--something like "$followOn". If $followOn is true (set that way for multi-step forms that can be shortcodes), the shortcode becomes the basepage. Otherwise, the site-wide basepage is it.

      Any other opinions?


          Issue Links



              • Assignee:
                andrewhunt Andrew Hunt
              • Votes:
                0 Vote for this issue
                3 Start watching this issue


                • Created: