0

For my wordpress content editor I need to specify the shortcodes I want to get executed. Is there a chance to define an array of shotcodes which get executed and all other shortcodes in the content which are not in the allowed array are getting ignored?

0

It's easier to remove specific shortcodes than it is to remove_all_shortcodes() and enable specific shortcodes.

To disable specific shortcodes from display everywhere, you would use the following:

<?php
add_filter( 'the_content', 'oxo_remove_shortcodes', 0 );

function oxo_remove_shortcodes( $content ) {

    /* Add the shortcodes that you would like to remove to the array below. */
    $shortcode_tags = array(
        'shortcode_1',
        'shortcode_2',
        'shortcode_3'
    );

    /* Remove each of the shortcodes listed above. */
    foreach ( $shortcode_tags as $shortcode_tag )
        remove_shortcode( $shortcode_tag );

    /* Return the post content without the shortcodes listed above. */
    return $content;
}

ALTERNATIVE

Depending on why you only want to enable a few shortcodes, you may be able to get away with creating a filter that checks if the content has_shortcode() from an array, and then strip_shortcodes() from the content, if it does not.

NOTE: a filter like that would be server intensive, and time consuming in terms of site performance.

  • Hey Courtney, thanks a lot! The problem i have is that i dont want to delete them instead they should show of as plain text unexecuted. My editor saves generated html so its necessary that specific shortcodes aren't executed. They will later get executed on the front end. I don't know why there isn't any balacklist or something like that. – Michael Oct 17 '14 at 1:52
  • Do you know the names of the shortcodes that you want to exclude? – Courtney Ivey Oct 17 '14 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.