NO BUG: Shortcode 503 Error

I’d been using the following code without error up until 1.9.3
I’d reverted back to 1.9.1 and it works as intended.
Had something changed in regards to how template shortcodes are called? Since 1.9.3, the blog posts this code applies to returns a 503 error.

I’d tested a plugin alternative (Ad Inserter – Ad Manager & AdSense Ads – WordPress plugin | however inserting the template shortcode produces the same 503 error.

if ( ! function_exists( 'add_shortcode_after_paragraph' ) ) {
    function add_shortcode_after_paragraph( $content ) {

        // Define the custom post types where you want to add the shortcode
        $allowed_post_types = array( 'post' ); // Only for blog posts

        // Check if the current page is a single post and if the post type is allowed
        if ( is_single() && in_array( get_post_type(), $allowed_post_types ) ) {

            // Define the first shortcode to insert (The Bricks section display settings for the this shortcode must be set to only display on mobile device size.)
            $first_shortcode = '[bricks_template id="706"]';

            // Define the second shortcode to insert (The second CTA shortcode is intended to display on desktop & mobile.)
            $second_shortcode = '[bricks_template id="809"]';

            // Split the content into paragraphs
            $paragraphs = explode( "</p>", $content );

            // Initialize a counter to keep track of paragraph number
            $counter = 0;

            // Loop through the paragraphs to find the right spots to insert the shortcodes
            foreach ( $paragraphs as $index => $paragraph ) {
                if ( trim( $paragraph ) ) {

                    // Insert the first shortcode after the 1st paragraph
                    if ( $counter == 1 ) {
                        $paragraphs[ $index ] .= $first_shortcode;

                    // Insert the second shortcode after the 7th paragraph
                    if ( $counter == 7 ) {
                        $paragraphs[ $index ] .= $second_shortcode;

            // Join the modified paragraphs back together
            $content = implode( "</p>", $paragraphs );

        return $content;

    // Add the filter to apply the function to the content
    add_filter( 'the_content', 'add_shortcode_after_paragraph' );

Hi @BenDudek,

Could it be that one of the templates themselves is breaking after updating to 1.9.3? Could you please share the error logs of the 503 errors you’re encountering?

Hi @charaf, apologies for the late reply.

I’ve done some testing and it appears to be an issue with Cloudways. I had contacted support, but they weren’t able to find anything in the log re: the 503 error.

I can run the same code calling a different template on my Litespeed shared hosting without any issue.
I’d also imported that template to my cloudways server, but the 503 error kept happening.

1 Like

Hm yeah that’s odd. They should’ve at least been able to share the error log of the 503 error. But glad you found a solution!