Reaching out for help, as my head is spinning! In my site I have the ability to dynamically generate pages and I use URL parameters to indicate the database and record to use to retrieve the information for display, artwork etc.

The page that uses these parameters, is a single page, but has the potential of display thousands of different versions, based on the records used.

The layout presently is: domain.com/details/?ls=00A&ls2=00B

BUT Facebook, does not play ball with sharing such a defined page. Thus I need to convert this into a virtual page that is more of this layout:

 Where parameter 1 is 00A and parameter 2 is 00B

I believer this has something to do with changing the rewrite rules or creating endpoints, but since the number of extensions off of the page called "details" can be thousands, that seems to defeat the point of dynamically generated pages and self maintenance.

How would someone recommend to achieve a wild-card effect of the extension:


It appears to be simular to this post: Passing & Reading URL Parameters with URL re-writing

Yet that post and other similar ones, are more geared toward a "Fixed" extension and I am looking for a wild card extension that can be read by custom code (via a shortcode) on the Details page.

Other posts, such as this: Facebook sharer and parameters in URL Gave no viable answer.

On the facebook from, I have all the open graph Meta tags modified via Javascript, after the fact and have confirmed the existance. It is just a matter of this virtual page using parameters as a definition.

Need some help.

UPDATE: This is the latest and it is still not working. Requesting help:

 add_action( 'init', 'DetailsEndPointRules' );
 function DetailsEndPointRules( )
    add_rewrite_tag("%ls%", '(\d+)');                    //database record 
    add_rewrite_tag("%lid%", '(\d+)');                   //List Id
    $tag   = '^details/(.+)/?$';    
    $regex = 'index.php?pagename=details&ls=$matches[1]&lid=$matches[2]';

   // add the url parameters to the query variable list  
   add_filter( 'query_vars', 'DetailsParametersVariables' );
   function DetailsParametersVariables( $vars )
    $vars[] = 'ls';
    $vars[] = 'lid';
    return $vars;
  • Modifying the meta tags with Javascript Is probably not sufficient. You need to make sure that they’re correctly generated based on the parameters. Whatever SEO plugin you’re using probably has filters for this. Changing the URL to not use parameters isn’t going to solve your problem if the meta tags and canonical URL appear identical. Nov 10, 2019 at 7:45
  • Yes, already doing that. But the parameters are necessary for click viability. Otherwise Facebook says the page is "bad". Parameters, for facebook share, are stripped off. Nov 10, 2019 at 7:46
  • It is a dynamic page. A reference, that is accepted by facebook, is necessary. So the parameters have to be converted into some kind of virtual page...and thus readable by the page code..in order to know what data to present. Nov 10, 2019 at 7:47
  • 1
    It doesn’t matter if it’s dynamic. If your SEO plugin is not aware of your parameters it’s going to report the page to Facebook as the same page regardless. Using JavaScript is not the right way to change the parameters. Nov 10, 2019 at 7:49
  • I turned off all the SEO (Yoast) and had the same issue. And I am not using Javascript to change the parameters, I am changing them to represent the title of the page and image displayed. Nov 10, 2019 at 7:49

1 Answer 1


With some struggle and a LOT of reading, the solution to facebook sharing issue is to use the wordpress rewrite option, but not a wordpress endpoint.

Endpoints are fixed additional options off of a single wordpress page. There is no room for expansion.

My site required single WordPress page, built on short-codes. This one page has the potential to display thousands of different content combinations. The url parameters were the index. But facebook, disliked indexes or parameters and indicate this in the Facebook developers guide lines.

BUT, you can trick Facebook, by changing WordPress rewrite rules, into what looks like an URL. The page does not actually exist, rather the URL now contains the same parameters, but in a different form.

Originally the page operated like this:


This is the format that is now rejected by Facebook, leading the shared page to come up as missing.

By turning the parameters into part of a standard URL such as:


The URL is accepted as is by Facebook.

Classic rule rewrite rules recommend the use of to modify content.

 add_filter( 'the_content', 'YourFunction' );

The problem with this is: Only one parameter can be associated with one piece of data and shortcodes require all parameters at the same time. Unless you want to use global variables and risk a race condition between different users, is not practical or content reliable.

Thus my solution, is to rewrite the rules within WordPress, only for this one particular page and then when the page is loaded and the short-code hit, "READ" the URL and parse it out, in order to retrieve the variables desired. The beauty of this solution is, you can add as many variables as you like. There is no limit.

The previous URL was this:


we now want the url to look like this



 add_action( 'init', 'wpd_detailspage_rewrite' );
 function wpd_detailspage_rewrite() 


     $pattern      = '^yourpage/([^/]+)/?';
     $ppagepattern = 'index.php?pagename=yourpage&option1=$matches[1]&option2=$matches[2]';
     add_rewrite_rule( $pattern,  $ppagepattern,  'top'  );

Then add this function, telling WordPress what parameter variables you are looking for:

     add_filter( 'query_vars', 'DetailsParametersVariables' );
     function DetailsParametersVariables( $vars )
       $vars[] = 'option1';
       $vars[] = 'option2';
       return $vars;

With your content shortcode code, then parse the URL.

  add_shortcode('PAGE_CONTENT', 'GenerateContent');
  function GenerateContent($atts)
   $base_url    = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' ? 'https' : 'http' ) . '://' .  $_SERVER['HTTP_HOST'];
   $current_url = $base_url . $_SERVER["REQUEST_URI"];

  $ClearUrl        = explode('?', $current_url);      // Clear any content attempts
  $ParametersShown = str_replace($url,"",$ClearUrl[0]);
  $BrokenUp  = explode('/', (string)$ParametersShown);
  $Option1   = sanitize_text_field(stripslashes($BrokenUp[0]));
  $Option2   = sanitize_text_field(stripslashes($BrokenUp[1]));

   if(!is_numeric ($Option1   ) || !is_numeric ($Option2   ))

      header('Location: /missing-page/');  
      return 0;



Some may say that using the $_SERVER call is insecure. But in this case, we are parsing and analyzing any content, like a pseudo fire-wall, so the risk is gone and potential removed.

The last REQUIRED step is to flush the rewrite rules. Nothing works unless this is in place. This can be done with a one shot of going to your Permalinks and re-saving. There are other solutions, but unless you are selling the plugin, not having the refresh overhead seems more practical for a custom site. If I come up with a better programmatic way of flushing, will update later.

You will see NO CHANGES in your .htaccess. This rule is saved in the Wordpress database. The saving causes the changes to be saved there.

With a URL of :


Facebook now accepts the link and is clickable to the generated page.

I put this code directly into my plugin, that generates all the content for the site. But could very easily be it's own independent plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.