• Before WordPress 5.0, we could add a custom shortcode by inserting the shortcode text ( for example: [mycustomshortcode] ) directly into the page/post. However, when I try to do the same now and add the shortcode created by my custom plugin to a page, the page does not get published and shows an error ‘Publishing failed’. I tried to use the WordPress Classic block and insert the shortcode in it with the same results. Interestingly, the shortcode is rendered properly when the page/post is viewed. Are there any further steps to be followed to make the custom shortcodes compatible with WordPress 5.0+ versions? My current version of WordPress is 5.0.2.

Viewing 4 replies - 1 through 4 (of 4 total)
  • hey @shrutijadhav,

    In the Gutenberg editor, click the plus button, search for Shortcode block. Add the shortcode you want to add to the editor, save and publish the post or page.

    Thanks !!!

    Thread Starter shrutijadhav

    (@shrutijadhav)

    Hi @arvindsinghu,

    Thank you for your reply!

    I have tried using both, classic as well as shortcode block in Gutenberg editor to add my custom shortcode. In my custom plugin, I have used add_shortcode() and a callback function displays a message, say, “Hi”. But when I try to save a page after inserting the shortcode that I have created in my custom plugin, I get the publishing failed message yet I am able to view the page and the message “Hi” is rendered using the shortcode on the page. I hope this helps in further understanding the issue.

    LOL Really? As if we are so stupid, we definitely would not think to try the shortcode block specifically intended to handle shortcode entry….LOL!
    Anyway, I am having the same issue…Don’t know what’s up with it. It seems as tho I had some issues a while back, and I somehow managed to alleviate them (not taking notes, regrettably) Until last night, I was not having any problems, as the shortcode block was handling any shortcode I threw at it. Even when I updated to 5.2, I don’t remember any prominent issues. Again, until last night.
    I tried a maneuver that I knew was sketchy, but wanted to try it to see if it could stand in as a nice hack. I can be weird that way, at times. Afterward, I could not publish a post or a page. Therefore, I had to do some housekeeping and got WordPress to publishing my content once, again. However, for some reason, whenever in some cases, the Gut. shortcode block will not allow me to publish.
    Similarly, to the instance above…I can build a form using a certain plugin…Upon completing the build, save the form and even view the form. Whenever, I copy the shortcode for the form, and go to create a new page or post, WordPress will not allow me to publish.
    Perhaps, you may be able to explain what is going on under the hood, so that I can avoid it, and work around it. I would also like to be able to use the forms shortcodes, also!
    With Respect,
    JimmyLove

    lachouetteinformatique

    (@lachouetteinformatique)

    @trulove : I had the same problem here.

    When adding some test shortcode in a post/page within a shortcode block, and trying to save/update the post/page, i got the red warning : update failed !

    The problem was comming from my shortcode : I was echoing stuff in the shortcode instead of returning it.

    Old not working version of my shortcode :

    <?php
    function shortcode_test($args) { ?>
      <div> shortcode test</div>
    <?php
    }
    
    add_shortcode('shortcodetest', 'shortcode_test');

    Working version :

    <?php
    function shortcode_test($args) {
      ob_start(); ?>
      <div> shortcode test</div>
      <?php
      return ob_get_clean();
    }
    
    add_shortcode('shortcodetest', 'shortcode_test');

    Here a link that helped me understanding the problem : Shortcodes Don’t echo, they return

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Making shortcodes work in WordPress 5.0+’ is closed to new replies.