Is there a way to disable links with JS or jQuery?

I was wondering if there is a way to disable a link using JS or jQuery, the links I want to disable are the ones in the portfolio items:

More details provided in the internal ticket.

Thanks in advance!

  • Ash
    • WordPress Hacker

    Hello Philipp Ludwig

    You can try the following JS:

    jQuery(function($){
    	$('.sc_services_item_title').each(function() {
    		$(this).find('a').attr('href', '#').click(function(e) {
    			e.preventDefault();
    			return false;
            });
        });
    });

    You can any custom CSS and JS plugin to apply this code. As a php code, you can try this:

    add_action( 'wp_head', function() {
    	?>
    	<script>
    		jQuery(function($){
    			$('.sc_services_item_title').each(function() {
    				$(this).find('a').attr('href', '#').click(function(e) {
    					e.preventDefault();
    					return false;
    				});
    			});
    		});
    	</script>
    	<?php
    } );

    You can use this code in your child theme's functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

  • Ash
    • WordPress Hacker

    Hello Philipp Ludwig

    Here is the JS code:

    jQuery(function($){
    			$('.sc_team_item_title').each(function() {
    				$(this).find('a').attr('href', '#').click(function(e) {
    					e.preventDefault();
    					return false;
    				});
    			});
    		});

    Here is the php code:

    add_action( 'wp_head', function() {
    	?>
    	<script>
    		jQuery(function($){
    			$('.sc_team_item_title').each(function() {
    				$(this).find('a').attr('href', '#').click(function(e) {
    					e.preventDefault();
    					return false;
    				});
    			});
    		});
    	</script>
    	<?php
    } );

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.