Is it possible to suppress an individual shortcode?

I am using the google maps plugin.

I am generating posts using data gathered in a form. This form includes an address which is entered into the [location] shortcode upon post creation.

I suspect the post creation is generating a map based on the shortcode in the post creation template, this combined with the created post results in two of the same maps.

My first solution is to suppress the [location] shortcode from executing when creating the post.

An alternate approach would be to add an action to the post creation that would immediately delete the map created in the template prior to the second map which is accurately associated with post.

I am hopeful the first solution is available...I have some memory of suppressing shortcodes, but I am not sure if I can do it on an individual basis, as I need other shortcodes to execute in the same post_create content.

Thank you for your consideration.

Jamie

  • Ivan

    Hey Jamie,

    Hope you are well and thanks for the question!

    I am not sure what exactly is your set up, but if you want to remove a shorcode you ould try the fallowing two solutions:

    1. This is a quick work around that would effectively hide the shortcode from appearing into your content. Simply paste the following code your child theme’s functions.php file:

    add_shortcode( 'shortcodetag', '__return_false' );

    2. Remove the already added shortcode then add the new empty shortcode on the init hook.

    function shortcode_cleaner() {
        remove_shortcode( 'shortcode' ); // Not exactly required
        add_shortcode( 'shortcode', 'my_remove_shortcode' );
    }
    add_action( 'init', 'shortcode_cleaner' );
    
    function my_remove_shortcode(){
        return '';
    }

    You will want to add this either to a child theme or suing plugin like this one - https://wordpress.org/plugins/code-snippets/
    to add your snippets.

    Let me know if this helps.

    Thanks,
    Ivan

  • jamie

    Thanks Ivan.

    This was resolved with I realized how the google map plugin can draw maps directly from the meta data, and I do not have to actually put the [location] shortcode into the content. I was wondering why I was getting two maps...issue resolved.

    On the same idea, though, I want to nest shortcodes into a [map].

    Like so:
    [map id="[meta value for agm_map_created"]

    Where the "meta value from agm_map_created" is represented by a shortcode like [meta data]

    [map id="[meta data]"]

    All i get is "] because the shortcode terminates on the wrong closing bracket.

    I have looked and saw sometimes

    [map id="{meta value for agm_map_created}"]

    sometimes works, but it did not work for me.

    I hope this makes sense :slight_smile:, but this issue is the next to last on my list for the whole map implementation. Hopeful for a solution. Perhaps there is easier way to reference meta data from within a post?

    Thank you,

    Jamie

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.