Title: Custom Permalink Setup
Last modified: November 9, 2023

---

# Custom Permalink Setup

 *  Resolved [johnbenedict](https://wordpress.org/support/users/johnbenedict/)
 * (@johnbenedict)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/custom-permalink-setup/)
 * Our website uses a custom permalink setup that goes something like this: Base
   URL > State based on Manual Input > Name (CPT) > which has a custom gallery of
   photos, each with their own permalink — so the structure of that link is base_url/
   state/name/photo_name
 * Out of the box — everything on our site works with the amp plugin — except for
   the photo pages. In order to fix those — we had a developer come up with a solution.
 * Unfortunately — that solution modified the AMP Plugin. I’ve been trying to find
   an alternative solution — such as moving this fix to our functions.php file —
   but so far no luck. I even consulted with ChatGPT (offered but non-working solutions
   below).
 * I have a strong feeling a dev familiar with this plugin could knock this out 
   no problem. Thank you in advance for anyone willing to take a stab at helping
   me out with this.
 * **Here is our current working solution:**
 * The file we edited is: [https://github.com/ampproject/amp-wp/blob/develop/src/MobileRedirection.php](https://github.com/ampproject/amp-wp/blob/develop/src/MobileRedirection.php)
 * The edit we made is:
 *     ```wp-block-code
       public function get_current_amp_url() {
   
       $url = $this->paired_routing->add_endpoint( amp_get_current_url() );
   
       $url = remove_query_arg( QueryVar::NOAMP, $url );
   
       # FIX
   
       $sep = "&";
   
       if (stristr($url, '?') === false) $sep = '?';
   
       foreach ($_GET as $k => $v) {
   
       $url .= $sep . urlencode($k) . "=" . urlencode($v); #$k=$v";
   
       $sep = "&";
   
       }
   
       return $url;
   
       }
       ```
   
 * **ChatGPT Solution 1:**
 * I see that you made an edit to the get_current_amp_url() method in the MobileRedirection.
   php file of the AMP for WordPress plugin. The change you made appends the current
   query parameters to the generated AMP URL.
 * To move this fix to your functions.php file, you can use the amp_post_template_data
   filter provided by the AMP for WordPress plugin. You can add this code to your
   theme’s functions.php file:
 *     ```wp-block-code
       function custom_amp_current_amp_url($data, $post) {
           $current_amp_url = $data['amphtml'];
   
           $sep = "&";
           if (strpos($current_amp_url, '?') === false) {
               $sep = '?';
           }
   
           foreach ($_GET as $key => $value) {
               $current_amp_url .= $sep . urlencode($key) . '=' . urlencode($value);
               $sep = '&';
           }
   
           $data['amphtml'] = $current_amp_url;
   
           return $data;
       }
   
       add_filter('amp_post_template_data', 'custom_amp_current_amp_url', 10, 2);
       ```
   
 * This code hooks into the amp_post_template_data filter, which allows you to modify
   the AMP URL. It replicates the same functionality you added to the plugin code
   by appending query parameters to the AMP URL.
 * After adding this code to your functions.php, the fix should work as intended,
   and you won’t need to edit the plugin code directly. Make sure to clear any caching,
   if you are using a caching plugin, for the changes to take effect.
 * **ChatGPT Solution 2:**
 * I apologize for the inconvenience. If the code I provided isn’t working as expected,
   let’s try another approach. You can override the get_current_amp_url method in
   your theme’s functions.php file. Here’s how to do it:
 * Open your theme’s functions.php file.
 * Add the following code:
 *     ```wp-block-code
       function custom_get_current_amp_url($url) {
           $sep = '&';
           if (strpos($url, '?') === false) {
               $sep = '?';
           }
   
           foreach ($_GET as $key => $value) {
               $url .= $sep . urlencode($key) . '=' . urlencode($value);
               $sep = '&';
           }
   
           return $url;
       }
   
       add_filter('amp_get_current_url', 'custom_get_current_amp_url', 10, 1);
       ```
   
 * This code hooks into the amp_get_current_url filter and modifies the AMP URL 
   in the same way you were doing in the plugin.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcustom-permalink-setup%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [johnbenedict](https://wordpress.org/support/users/johnbenedict/)
 * (@johnbenedict)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/custom-permalink-setup/#post-17201447)
 * Anyone? Any ideas?
 *  Plugin Support [Milind More](https://wordpress.org/support/users/milindmore22/)
 * (@milindmore22)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/custom-permalink-setup/#post-17218045)
 * Hello [@johnbenedict](https://wordpress.org/support/users/johnbenedict/)
 * Sorry for the delayed response, This sounds like it needs a custom solution we
   will recommend checking with one of the [AMP expert](https://amp-wp.org/ecosystem/amp-experts/?order=asc&orderby=name)
   s who can provide you with customized solutions
 *  Plugin Support [Milind More](https://wordpress.org/support/users/milindmore22/)
 * (@milindmore22)
 * [2 years, 6 months ago](https://wordpress.org/support/topic/custom-permalink-setup/#post-17241146)
 * [@johnbenedict](https://wordpress.org/support/users/johnbenedict/) As we didn’t
   receive a response I’ll mark this as resolved. Feel free to open a [new support topic](https://wordpress.org/support/plugin/amp/#new-post)
   if you require any further assistance.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom Permalink Setup’ is closed to new replies.

 * ![](https://ps.w.org/amp/assets/icon.svg?rev=2527602)
 * [AMP](https://wordpress.org/plugins/amp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amp/)
 * [Active Topics](https://wordpress.org/support/plugin/amp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amp/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Milind More](https://wordpress.org/support/users/milindmore22/)
 * Last activity: [2 years, 6 months ago](https://wordpress.org/support/topic/custom-permalink-setup/#post-17241146)
 * Status: resolved