WordPress easily be able to add shortcode to insert PHP codes. When I added a shortcode which can make a list of specific posts. After that, comments form below shortcode can’t be removed. Why?

First, Added a hook of shortcode into the function.php. Then added a list.php file which will be listed a specific posts.

list.php

Finally, added a shortcode, [myphp file=”list.php”] ,into page and reload. Comments form displayed. Why? I understand that to prohibit display a comment form, uncheck “Allow comments” of Discussion in the Edit page. Of course, it did.

Conclusion is $post context was override by specific posts. In short, comments_open() function doesn’t check right context.

To temporary fix this issue, before read specific posts, context has been saved, and end of process, it been restored.

Hope this will help you 😗