• Is there a way I can set up a hook like this to remove a specific shortcode in 20 seconds?

    I found this code online … but I don’t know how to execute it. I’ve added it to the functions.php … but I’m not sure what to replace wp_footer with.

    add_action( 'wp_footer', 'remove_content_timer' );
    function remove_content_timer() {
    	?>
    	<script type="text/javascript">
    
    	setTimeout(function() {
    		// run the necessary javascript to remove the content
    	}, 20000); // run function after 20000ms
    
    	</script>
    	<?php
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • is the JavaScript showing up at the bottom of your source code?

    If so, then you need to write some JavaScript code to remove the content from the page.

    This would replace the comment that says ‘// run the necessary javascript to remove the content’ with the correct code.

    Thread Starter AmandaEve

    (@amandaeve)

    Sorry – I’m not sure what you mean.

    I thought I’d add that code to the functions.php file. and then somehow call it from my posts or pages.

    I was wondering how I’d call it.

    If I have a piece of shortcode that shows an image, but I wanted the image to go away after 20 seconds.

    What would I put in the actualy page to remove that shortcode?
    ex:
    [remove_content_timer][show image="image.gif"][/remove_content_timer]

    note: I’m sorry – I’m clueless.

    Thread Starter AmandaEve

    (@amandaeve)

    could I use this in wordpress?
    http://jsbin.com/aguyuw/1/edit?html,js,output

    Hmm. A shortcode in WordPress is used to output HTML into the page. So, when you put a shortcode like [gallery id='1,2'] (the WordPress Shortcode to insert a gallery from the Media Library) it outputs a bunch of html. If you do a “view source” you can see what that HTML looks like.

    The JSbin code you pasted would work – but you’ll need to figure out what the HTML is that is being output by the shortcode, and you’ll then need to address that DOM element and remove it from the page.

    This line here:

    $('#target').remove();

    Removes the following HTML:
    <p id='target'>Foobar</p>

    But you’ll have to figure out the SPECIFIC HTML in YOUR page to remove.

    Thread Starter AmandaEve

    (@amandaeve)

    oh. thanks. I’ll maybe look for another option. #OverMyHead

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

The topic ‘Remove Shortcode Hook’ is closed to new replies.