• Resolved treytallent

    (@treytallent)


    Hello, when using the code provided in the docs I get an error ” Uncaught Error: Undefined constant “wp” in …”

    How do I run this code?

    edit: I realised that the provided code is for Javascript, it now runs but it does nothing.

    • This topic was modified 1 month, 1 week ago by treytallent.
    • This topic was modified 1 month, 1 week ago by treytallent.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here are a few steps to troubleshoot and ensure the code runs correctly:
    1. Ensure WordPress Environment: Make sure your JavaScript code is running within a WordPress environment.

    2. Enqueue Scripts Correctly: If you’re adding this code to your theme or plugin, ensure you are enqueuing your scripts correctly using wp_enqueue_script() in your PHP code. For example:
    function my_enqueue_scripts() {
    wp_enqueue_script('my-script', get_template_directory_uri() . '/js/my-script.js', array('wp-api'), '1.0', true);
    }
    add_action('wp_enqueue_scripts', 'my_enqueue_scripts');


    3. Check for Dependencies
    4. Console Log for Debugging
    console.log('Script loaded');
    // Your existing code…

    5. Check for Errors in the Console: Open your browser’s developer console (usually F12 or right-click -> Inspect -> Console) and look for any JavaScript errors that might indicate what’s going wrong.

    Thread Starter treytallent

    (@treytallent)

    @mayur6740 thank you. I have a JS script enqueued correctly, but the code provided in the reference guides still has no effect. Other people have had this issue and solved it by using wp. domready() to call the unregister block function, but this does not work for me. I have also tried enqueueing the JS script with the wp-api, wp-blocks and wp-dom dependencies

    edit: solution was found here using the block_type_metadata filter hook https://github.com/WordPress/gutenberg/issues/25330#issuecomment-2143405764

    • This reply was modified 1 month, 1 week ago by treytallent.
    • This reply was modified 1 month, 1 week ago by treytallent.
    • This reply was modified 1 month, 1 week ago by treytallent.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.