1
votes

I am working on a cardealer website but there is a problem with the URL/permalink. When you want to share the page it doesn't use the actual URL but the permalink set on the page. I know this sounds logical but the URL is created in a external PHP file. This PHP file get's the information of the car out of the database and shows it on the page. The actual URL also get's build in this PHP file. So the permalink set in WordPress is a default and the actual URL is what I would like to share.

Permalink set in WordPress: This is the permalink set in WordPress

Actual URL on the page: Actual URL on the page

So if someone shares this page I want to send the actual URL (https://www.prinsauto.nl/vakgarage-aanbod-details/audi-a6-avant...) but not the permalink. Again, the actual URL is build in a PHP file.

How can I do that?

1
You could try just setting a URL in Open Graph meta. <meta property="og:url" content="https://www.prinsauto.nl/vakgarage-aanbod-details/audi-a6-avant" /> - DubVader
Are you trying to create a page with a static template but it's content is generated dynamically by running a query against a custom db table. Query is built from the URL? - user1165759
@DubVader Thank you for your answer. I tried this but didn't work. - Bas
@user1165759 Yes! - Bas

1 Answers

1
votes

WordPress is not very easy when it comes to custom URLs. Viewing the code of the template-loader.php file, it seams that you could use a template file to run your page functionality.

As can seen in the code (line 77) you can use the template_include filter in your plugin (or template's functions.php file) to check for your specific "route" and return the template file to load.

Example:

add_filter('template_include', 'your_function_name', 0, 1);

function your_function_name($template) {
  $uri = $_SERVER['REQUEST_URI'];
  if (strpos($uri, 'vakgarage-aanbod-details') !== false) {
    return 'template-file-name.php';
  }
  else {
    return false;
  }
}

All the PHP logic you described in your question should go in included template file.