• I have a collection of several thousands of nature photos.

    1. In Godaddy WordPress I was able to dynamically display 100 images thumbnails using [mla_gallery] filtering a theme (for example, mountains, rivers, etc.) successfully.
    2. Next, click on a thumbnail, it would open a photo page that displays a large photo and its description.  There is a link on this page pointing to a page that allows user buy print.
    3. On the Purchase photo page, a user can choose from different sizes (and prices) of a photo, and click on add to cart.

    I wasn’t successful in step 3) because when I tried to add a section of php code using Code

    Snippet plugin, the site crashed. The front page displays “There has been a critical error on this website.” even though the front page doesn’t use any snippet. I can’t access the WordPress dashboard because the access also crashed with the same message “There has been a critical error on this website.” I had to text Godaddy support. They uninstalled all plugins (code snippet and WooCommerce). Website came back. They told me to reinstall and get e clean copy of everything.  I did reinstall and the site crashed again. Contacted Godaddy and got the site back.

    Now my question is: shall I avoid Woocommerce and only use php code to dynamically display the large image, to connect a shopping cart?  After the site crashed two times, I am reluctant to use short code in php to connect to a WooCommerce. Can I go directly to Paypal?

    What’s the best practice? I’d like to display all the images dynamically, the to build the Purchase Image page dynamically.

    Thanks in Advance.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Rather than continually crashing a live site,, it is best practice to create a copy ( often called staging ) site, Then you can try trhing directly and if if crashes you can just re copy. Your host MAY provide staging sites – there are also plugins that create staging sites. https://wordpress.org/plugins/search/staging/

    One you have a safe space you can try your solutions. A key partis to set up debug logging so when you get a crash you can analyse why, see also https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/

    Moderator threadi

    (@threadi)

    You can’t do without WooCommerce, since you need it to sell your photos. My guess is that the PHP code you’re using is faulty. Can you show it to us? Use the code block here in the forum: https://wordpress.org/support/forum-user-guide/block-editor/#code-block

    Thread Starter allmighty2026

    (@allmighty2026)

    Allen and threadi,

    Thank you both for reply. I’m back to the site and dashboard. I was able to locate the error message in the error log:

    PHP Fatal error: Uncaught Error: Call to a member function get_page_permastruct() on null in /dom1149977/wp-includes/link-template.php:435
    Stack trace: 0 /dom1149977/wp-includes/link-template.php(397): _get_page_link(Object(WP_Post), false, false) 1 /dom1149977/wp-includes/link-template.php(197): get_page_link(Object(WP_Post), false, false) 2 /dom1149977/wp-content/plugins/woocommerce/includes/wc-page-functions.php(98): get_permalink(Object(WP_Post)) 3 /dom1149977/wp-content/plugins/woocommerce/includes/wc-core-functions.php(1410): wc_get_page_permalink(‘cart’) 4 /dom1149977/wp-content/plugins/code-snippets/php/snippet-ops.php(663) : eval()’d code(4): wc_get_cart_url() 5 /dom1149977/wp-content/plugins/code-snippets/php/snippet-ops.php(663): eval() 6 /dom1149977/wp-content/plugins/code-snippets/php/evaluation/class-evaluate-functions.php(170): Code_Snippets\execute_snippet(‘\n$product_id = …’, 9) 7 /dom1149977/wp-content/plugins/code-snippets/php/evaluation/class-evaluate-functions.php(150): Evaluation\Evaluate_Functions->evaluate_db_snippets() 8 /dom1149977/wp-includes/class-wp-hook.php(341): Evaluation\Evaluate_Functions->evaluate_early(”) 9 /dom1149977/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters(NULL, Array) 10 /dom1149977/wp-includes/plugin.php(522): WP_Hook->do_action(Array) 11 /dom1149977/wp-settings.php(593): do_action(‘plugins_loaded’) 12 /dom1149977/wp-config.php(54): require_once(‘/dom1149977/wp-…’) 13 /dom1149977/wp-load.php(50): require_once(‘/dom1149977/wp-…’) 14 /dom1149977/wp-admin/admin.php(35): require_once(‘/dom1149977/wp-…’) 15 /dom1149977/wp-admin/plugins.php(10): require_once(‘/dom1149977/wp-…’) 16 {main}

    thrown in /dom1149977/wp-includes/link-template.php on line 435

    I am still looking for a way to access the php code. I can see in the phpAdmin database the entry of the php code. On hte internet, there are suggestions saying code is bad, trying to call the function wc_get_car_url() before the plugin was loaded…

    Moderator threadi

    (@threadi)

    Thank you very much for the error log. It’s already clear from this that a specific PHP code snippet appears to be causing the error. I’d therefore still like to know more about the PHP snippet you inserted there?

    Thread Starter allmighty2026

    (@allmighty2026)

    $product_id = 123;

    $add_to_cart_url = wc_get_cart_url() .
    '?add-to-cart=' . $product_id .
    '&image_file=' . urlencode($filename);

    ?>

    <a href="<?php echo esc_url($add_to_cart_url); ?>" class="button">
    Add To Cart
    </a>

    The above is the code. I realize one problem is that $add_to_cart_url is not ready yet.

    There are suggestions to add a delay to call wc_get_cart_url()

    add_action( 'template_redirect', 'my_custom_redirect_function' );

    function my_custom_redirect_function() {
    // WordPress is fully loaded now
    $cart_url = wc_get_cart_url();
    // ... your other code here
    }

    Does it look right? Any help will be greatly appreciated!

    Moderator threadi

    (@threadi)

    The code above uses an unknown variable named $filename. However, if you insert the code exactly as it appears here as a code snippet, it will immediately cause an error. The reason is that it uses the function wc_get_cart_url(), among other things, which simply doesn’t exist when executed in isolation without any context.

    You need to execute this code within a specific context. This is typically done using hooks in WordPress. So the question is: where do you actually want to execute this code? In other words, where on the website should this generated link be placed? Depending on that, one can tell you which hook is suitable for this purpose. However, the template_redirect hook seems incorrect to me in this context.

    Thread Starter allmighty2026

    (@allmighty2026)

    I haven’t incorporated the code into WordPress yet. I added a snippet (which I posted earlier). When I saved it, the site crashed. The snippet was used in any page yet. Isn’t that interesting. In the past, errors showed on the page it had problems, it wouldn’t crash the whole site. And in this case, I haven’t plugged into the WordPress page. Simply creating it would cause an error like that.

    Here is the scenario: I have tons of images. I moved 100 to the Media Library in WordPress. Each image has title, filename, caption, description, etc.

    Using <mla_gallery> tag, I selected 25 images with “clouds” in the file name. I displayed the the thumbnails of these 25 in a page called “Photo.” I deliberatly call the page “Photo” because I’ll use the same page to display “Sunshine” using the same method.

    On the Clouds page, clicking on a thumbnail would opens the Photo page that dispalys a large image of hte photo, with a button that says “Buy photo.” Here is the snippet:

    function get_display_photo_shortcode() {

    $name = isset($_GET['image_name']) ? sanitize_text_field($_GET['image_name']) : '';
    $page = isset($_GET['from']) ? sanitize_text_field($_GET['from']) : '';
    $caption = isset($_GET['caption']) ? sanitize_text_field($_GET['caption']) : '';

    ob_start();
    ?>

    <div>

    <img src="https://mysite/wp-content/uploads/2026/05//<?php echo esc_html($name); ?>" alt="Description of the image">
    <p><?php echo esc_html($caption); ?></p>
    <!-- <p>Page: <?php echo esc_html($page); ?></p>-->
    <p> <a href="/buy-photo/?file=<?php echo urlencode($name); ?>">
    Buy photo
    </a>(coming soon) &nbsp;&nbsp;
    <a href="/cloud_static/">Purchase Test</a>&nbsp;&nbsp;
    <a href="https://mysite/<?php echo esc_html($page); ?>">Back</a>
    </div>

    <?php
    return ob_get_clean();
    }

    On hte Buy photo page, I’d like to display three options of sizes and their prices of the physical print of the photo. Then display a “Add to Cart” button, which I was hopeing to use the above snippet. The “Add to Cart” takes the flow to WooCommerce. The Buy photo page should work for all images. The “Purhcase Test” link (<a href=”/cloud_static/”>Purchase Test</a> works because it was pointing to a product (static) registered in the WooCommerce product list. I’d like Buy photo link works for all images dynamically.

    Does it make sense?

    Moderator threadi

    (@threadi)

    Yeah, I see. That’s an interesting project, and I totally get it.

    So you want to add another button to the “Buy Photo” page. What kind of page is that? Did you create it yourself as a standalone page, or is it a WooCommerce single product page?

    I added a snippet (which I posted earlier). When I saved it, the site crashed.

    Of course, the code is executed exactly as written, without the functions it requires having been declared beforehand. I don’t know why it used to work for you. It might be a setting in the code snippet plugin you’re using. Or maybe you used to insert the code differently. In any case, based on what I’ve read here, this approach definitely won’t work and will result in exactly this error.

    Thread Starter allmighty2026

    (@allmighty2026)

    Thanks for your patience.

    Called GoDaddy to uninstalled code snippet and woocommerce. The site was up. I intalled them again. the site crashed. Call Godaddy to do the same. Site up. Intalled code snippet and woocommerce. Site down.

    I was able to access Setting (not the WP dashboard), and there was the phpAdmin database. I found the snippet datatable, and the snippet I added yesterday. I deleted the snippet. This was the only way to remove it, and I didn’t know if it worked. After I removed it, I installed code snippet. it crashed again.

    Called Godaddy to bring hte site up. They did and warned me not to install code-snippet. I said I had to have it because I needed it to do the dynamic page. Then on the internet, I found someone suggesting going to mydomain/admin and running it in safe mode to reload. I did that. Then the snippet was back in WordPress (I didn’t install again), and the one snippet that worked before yestersday was work. Teh bad one was gone.

    I need to have a more stable way to deal with this matter.

    Will update on the next step.

    Thread Starter allmighty2026

    (@allmighty2026)

    My site is up now, after removing the bad code snippert from the phpAdmin database.

    I’ve been experimenting with WooCommerce product. There is a way to upload many photos (30,000) and for each photo WooCommerce creates a product.

    I prefer not to have so many products in WooCommerce. Some of hte photos might never be purchase. I’d like to have dynamic product template. each time calling hte product page, the photo filename is passed from the previous page, and this product template displays the photo, and offers three size and prices for physical print. Then an “Add to Cart” button take the purchase to the cart.

    I read about the steps: changes in function.php, creation of a hidden product in WooCommerce, then change of product (photo name each time going in). Is that a good approach?

    Thanks!

    Moderator threadi

    (@threadi)

    I recommend getting in touch with WooCommerce’s support about this via https://woocommerce.com/my-account/create-a-ticket/ if you have any of their paid WooCommerce products or https://wordpress.org/support/plugin/woocommerce/ if you do not.

Viewing 11 replies - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.