Support

Account

Home Forums Gutenberg Prevent clicks on anchors

Unread

Prevent clicks on anchors

    • powerj

    • November 19, 2020 at 3:01 pm

    I have built an ACF Block that loads posts in a grid. Each post in the grid is clickable. Working fine except that in the editor you can accidentally activate the links taking you off to the posts while you are trying to edit.

    In order to prevent the clicks, I’ve implemented the following code but I can’t get any jquery to apply, although I can confirm the file is definitely loading in the header. I realise you can load js using register_block_type(), but as I want to prevent clicks on any links on any blocks in the editor, it makes sense to enqueue from functions.php.

    functions.php

    	//* Enqueue Gutenberg styles 
    		wp_enqueue_script( 'testJs', get_bloginfo( 'stylesheet_directory' ) . '/js/test.js', array( 'jquery'));
    	}

    test.js

     jQuery( function($) {
        'use strict';
    
    // Stop links from activating in the editor
    $("a").click(function(event){
        event.preventDefault();
      });
    
    });

    What am I missing .

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.