• How do I prevent short code from running on the page before a user makes a selection from a drop down ? I have a php function in functions.php that calls a python script for some analysis. The output is pasted on the screen in a big block of text. I want to format the output so its nice and separated into paragraphs and clean to read. The issue also is that the short code I wrote to call the python script is always executed upon page load. So to the screen it displays invalid comparison ran, because the user hasn’t selected the options. I want to make it so that the screen only shows the correct formatted text after a user makes a selection

Viewing 1 replies (of 1 total)
  • To address your requirements I’m afraid you’d need to modify the behavior of your shortcode so it only executes after the user has made a selection from a dropdown menu. This usually requires some JavaScript to handle the user interaction and AJAX to process the shortcode execution server-side only after the dropdown is changed. You can:

    1. Add a PHP function in functions.php to check if it’s being triggered by an AJAX request.
    2. Add JavaScript to your theme to handle the dropdown change and initiate the AJAX request.
    3. Formatting the output can be managed by another PHP function after the Python script’s output is captured. Use PHP functions like nl2br() (for converting newlines to <br> tags) and esc_html() (to escape HTML entities and ensure security)

    Alternatively, you can use scripts for this, or parts of it. For instance:

    AJAX Load More is a popular plugin that allows you to load posts, pages, comments, and other content with AJAX queries. You can customize it to work with shortcodes and trigger actions based on user inputs such as selections from a dropdown.

Viewing 1 replies (of 1 total)
  • The topic ‘Formatting text to the page and Issue with displaying of shortcode on page load’ is closed to new replies.