• Resolved kailaf

    (@kailaf)


    Hi,
    I am very new to webpages development in WordPress.
    Scenario: list of thumbnails -> client clicks on a thumbnail -> opens a page with embedded pdf.
    Approach: Crated a page with shortcode to embed pdf. I am sending query string of the pdf file location to this page.
    Problem: Not understanding how to set the src attribute in shortcode

    Any suggestions are greatly appreciated. What things I need to know to solve this problem.

    thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • What is the code you’ve written till now.

    Moderator bcworkz

    (@bcworkz)

    The needs of shortcodes are unique to the shortcode. You’ve not given us enough information.

    From your description, I’m skeptical that shortcodes are the best solution. I’d think a template that queries for PDF attachments and which generates the list from the results would be a better approach. Each thumbnail would be a link to the respective PDF file. Most browsers will automatically open the file when the link is followed.

    N.B. WordPress does not generate PDF thumbnails by default. They’ll need to be generated through other means.

    Thread Starter kailaf

    (@kailaf)

    Hi,

    Thank you very much for responding.

    The shortcode I am using looks something like this:
    [pdf_plugin src=”https://abc.com/wp-content/1.pdf”%5D

    I want to dynamically change src based on the thumbnail clicked. For that, I added a custom url of a wp-page, followed by a query string of pdf-file url in the thumbnail(image) link.

    This wp-page has slightly modified version of above shortcode that calls another plugin to get query string parameters, something like this:
    [pdf_plugin [url_parameters attr=src param=query_string_name]]

    Result: The shortcode appears on the wp-page with query string value filled in for src parameter. But the pdf is not embedded.

    Sorry if this is a straight forwarding thing to do. Please tell me what I am missing/doing wrong.

    Thank you.

    Moderator bcworkz

    (@bcworkz)

    Shortcodes run server side. Click events happen client side, so there is not a direct relationship. The only way to accomplish something would be via a HTTP request. If there has to be a request, why not retrieve the file directly instead of running more server code that eventually requests the file anyway?

    It’s impractical (but not impossible) to dynamically insert data into shortcode attributes. The attributes are intended to be static. For server side code to respond to a click event, some sort of unique data has to be passed in the HTTP request. It’d be better if the shortcode handler were expecting this data and it got the data for itself without having to be passed via attribute.

    Thread Starter kailaf

    (@kailaf)

    Hi,

    Thank you again for responding.

    I was creating wp-page for each pdf and linking it to the thumbnail image.
    But there are too many pdf files to work with. So I was thinking may be there is a way to have a template-page with the pdf embed shortcode whose src can be dynamically changed for thumbnail click.

    Is there any other way of doing this?

    Thank you.

    Can you post the URL of the pages in question?

    Moderator bcworkz

    (@bcworkz)

    Develop a custom coded page template. Templates can do nearly anything a shortcode would accomplish and more. The exception is shortcodes are better at inserting their output at any desired place within post content. If the desired output is before or after (or instead of) post content, a template is the better choice.
    https://developer.www.ads-software.com/themes/template-files-section/page-template-files/

    Thread Starter kailaf

    (@kailaf)

    Hi,
    Thank you so much for the link. It was helpful.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘change src attribute of shortcode based on user click’ is closed to new replies.