i need a little help to with this issue:

I have a string wich contains shortcodes like [shortcode data="1" data2="2"] How I can extract with regex? without wordpress system?

Thanks in advance.


Where is this string located ? I know you wrote "without wordpress system" , but WordPress has a function get shortcode regex

If you really want to avoid it for some reason, the following example might help you :

// check the post for a short code 
function check_shortcode( $shortcode = NULL ) {

    $post_to_check = get_post( get_the_ID() );

    // Until we search, set false 
    $found = false;

    //  no short - FALSE
    if ( ! $shortcode ) {
        return $found;

    // check the post content for the short code 
    if ( stripos( $post_to_check->post_content, '[' . $shortcode) !== FALSE ) {
        // we have found the short code
        $found = TRUE;

    // return our final results 
    return $found;

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.