Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8544735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:37:56+00:00 2026-06-11T12:37:56+00:00

So another nested shortcodes problem. I have two shortcodes : [slide] and [prg]. They’re

  • 0

So another nested shortcodes problem.
I have two shortcodes : [slide] and [prg]. They’re both enclosing shortcodes. [prg] is nested into [slide]. But [prg] isn’t interpreted.
The two shortcodes work well separately.
I know the do_shortcode() function but it seems not working, I don’t know why.

Here’s the code I’ve write :

add_action( 'init', 'register_shortcodes');

function make_slide($atts, $content = null) {
    extract(shortcode_atts(array(
      'num' => 1,
   ), $atts));

    $post_title = get_the_title($post->ID);
    $wrap = '<div class="slide slide-'.$num.'"><h1 class="h2-like projet_title">'.$post_title.'</h1>'.$content.'</div>';
    return $wrap;
}

function wrap_paragraph($atts, $content = null)
{
    $content = do_shortcode($content); //I've tried several solutions but none've worked.
    return '<p>'.$content.'</p>';
}

function register_shortcodes(){
    add_shortcode('slide', 'make_slide');
    add_shortcode('prg', 'wrap_paragraph');
}

And here’s the content of my post (a custom post type) in the html editor :

[slide num="1"]<img title="4a6c2a605946a_1080x733" src="http://localhost:8888/labs/noway/wordpress_1/wp-content/uploads/2012/09/4a6c2a605946a_1080x733-460x312.jpg" alt="4a6c2a605946a_1080x733" width="460" height="312" />

[prg]Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa.[/prg][/slide]

I’ve read several posts on this site and other ones such as sitepoint.com and speckyboy.com, as well as the wordpress codex but the answers doesn’t work for me.
Perhaps it’s just because i’m not implementing shortcodes the right way in my function.php file?

If anybody can help me ? I really want to understand what makes it not working. Thanks a lot in advance.
Sorry for my bad english, I hope I’m understandable.

EDIT
I’ve stupidely validated my comment before finishing it, so there it is :

Hi @maiorano and thanks a lot for your help, it worked perfectly.
However even if your code is really good, I can’t use it as it is because I need to get the pictures directly from the media library, with as less as possible human intervention in the MCE editor. But it has made me learn a godd way to go.

Also I’ve tested to use do_shortcode into the top-level shortcode, but it produced a weird result : my < p > was deported outside of the < div > so I was confused.

So it appears that what was blocking me was a combination of that top-level do_shortcode-ish and perhaps the fact that my add_shortcode() were declared after the shortcodes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:37:57+00:00Added an answer on June 11, 2026 at 12:37 pm

    The problem is that your top-level shortocde “[slide]” is not executing do_shortcode() on its content. A few pointers:

    I would advise including your image attributes as shortcode attributes, as it reduces the amount of markup and provides you the ability to define defaults.

    You also don’t need to define your shortcodes within an ‘init’ callback. It can be done in global scope:

    add_shortcode('slide', 'make_slide');
    add_shortcode('prg', 'wrap_paragraph');
    function make_slide($atts, $content = null)
    {
        extract(shortcode_atts(array(
          'num' => 1,
          'title' => false,
          'src' => get_bloginfo('stylesheet_directory').'/images/notfound.jpg', //Default image if none provided
          'alt' => false,
          'width' => false,
          'height' => false,
       ), $atts));
    
        $title = $title ? " title=\"$title\"" : '';
        $alt = $alt ? " alt=\"$alt\"" : '';
        $width = $width ? " width=\"$width\"" : '';
        $height = $height ? " height=\"$height\"" : '';
    
        $img = "<img src=\"$src\"".$title.$alt.$width.$height." />";
    
        $post_title = get_the_title($post->ID);
        $wrap = '<div class="slide slide-'.$num.'"><h1 class="h2-like projet_title">'.$post_title.'</h1>'.$img.do_shortcode($content).'</div>';
        return $wrap;
    }
    
    function wrap_paragraph($atts, $content = null)
    {
        $content = do_shortcode($content); //This is fine if you plan on nesting shortcode within this callback
        return '<p>'.$content.'</p>';
    }
    

    Using this, I was able to add the content:

    [slide num="1" title="4a6c2a605946a_1080x733" src="http://localhost:8888/labs/noway/wordpress_1/wp-content/uploads/2012/09/4a6c2a605946a_1080x733-460x312.jpg" alt="4a6c2a605946a_1080x733" width="460" height="312"][prg]Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa.[/prg][/slide]
    

    And get:

    <div class="slide slide-1"><h1 class="h2-like projet_title">Hello world!</h1><img width="460" height="312" alt="4a6c2a605946a_1080x733" title="4a6c2a605946a_1080x733" src="http://localhost:8888/labs/noway/wordpress_1/wp-content/uploads/2012/09/4a6c2a605946a_1080x733-460x312.jpg"><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa.</p></div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

another problem. I have already placed my Jython.jar into what my computer recognizes as
If I have an element (html) nested in another element and both of them
So I have a loop to be nested inside another loop based on two
I have 2 resources, one being a nested resource of another: parent_resource and child_resource
I have a model, ModelRun , that accepts nested attributes for another model, ParameterValue
I have an asp.net page with a multiview control nested within another multiview control.
I want to catch an exception, that is nested into another exception. I'm doing
I have a struct that's inside an array that is nested inside another struct,
I have a table nested inside of a another tables <td> . When a
I have an element nested inside another element (i.e. parent element). The thing is,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.