Support » Fixing WordPress » Modify shortocode in page by url

  • Is it possible to modify the shortocode of a page by readinng an url ?
    Something like this: one page/post with a shortcode like this :
    [this is a shortocode with variable $var] and replace $var by reading an url like https://link/to/page/?var ?
    The idea is to make 1 unique page to embed my pdfs, and pass the pdf to embed when calling the page/post with its url. And avoid to have one page per embedded pdf.
    Thanks !

    • This topic was modified 1 week, 1 day ago by klinik.
    • This topic was modified 1 week, 1 day ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The do_shortcode() process is hooked into “the_content” filter. If you hook in before this happens, you could find the shortcode in content and alter its attribute value. Not very efficient, but it’s feasible.

    A better approach would depend on how the shortcode handler function is written. There may be a filter where you can alter passed attribute values to cause the function to fetch the desired PDF instead of whatever the attribute value specifies.

    If such a filter is not available, a third option would be to create your own shortcode using the existing one as a starting point, altering as needed to get the PDF reference from the request URL instead of a passed attribute.

    Yet another possibility would be to create a custom page template that fetches the right PDF, bypassing the need for a shortcode at all. These all require custom coding, but are the best options where a lot of PDFs are involved.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.