
Commentcode API lets you generate custom outputs with HTML comment-like codes.
It is similar to the Shortcode API except it takes a form of HTML comments and some few features.
Since it takes a form of HTML comments, even the user disables your plugin, the embedded code will not be visible, on contrary to shortcodes that remain in posts when their plugins are deactivated.
Say, you have been using a plugin that converts a plugin specific shortcode into custom outputs. Later you found something else that is more useful and uninstalled it.
But the shortcodes used by that plugin remained in hundreds of posts and it was too much work to manually delete them so you have to ask somebody to run SQL commands.
That’s a problem. What if the shortcode takes a form of an HTML comment? It won’t leave such a mess.
It looks like this.
<!--- tag foo="bar" ---> <!--- tag color="#333" ---><p>Some outputs.</p><!--- /tag --->
Notice that tripe dashes are used in the both opening and closing part. So it won’t hardly conflict with generic HTML comments.
The shortcode cannot pass multi-dimensional arguments to the callback function.
The below attributes won’t be parsed.
[my_shortcode foo[1]="one" foo[2]="two"]
However, commentcode can handle it.
<!---my_shortcode foo[1]="one" foo[2]="two" --->
The attributes are interpreted as
array( 'foo' => array( 1 => 'one', 2 => 'two', ) )
The shortcode does not allow capitalized attribute names.
[my_shortcode CapitalName="I need it to be capitalized"]
The attribute is interpreted as
array( 'capitalname' => 'I need it to be capitalized', )
This is not useful when you need to perform remote API requests which require argument names with capital letters.
However, the commentcode API preserves those argument names.
<!--- my_shortcode CapitalName="Please keep capitalization!" --->
will be
array( 'CapitalName' => 'Please keep capitalization!', )
Use the add_commentcode() function. It accepts two parameters.
1. (string) the commentcode tag.
2. (callable) a callback function which gets called when the commentcode of the specified tag is processed.
The callback function receives three parameters.
1. (string) The filtered text, usually an empty string.
2. (array) The attributes set in the commentcode.
3. (string) The commentcode tag name.
function get_my_commentcode( $text, $arguments, $tag ) { return "<pre>" . htmlspecialchars( print_r( $arguments, true ) ) . "</pre>"; } add_commentcode( 'my_commentcode', 'get_my_commentcode' ); For a test, while running the above code, try inserting <!---my_commentcode Foo="bar" numbers[ 1 ]="one" numbers[ 2 ]="two"---> in a post.
It will produce this output,
Array ( [Foo] => bar [numbers] => Array ( [1] => one [2] => two ) )
Starting from $0 per month.
Rating
Reviewers
No reviews
Tags
Developed By
Michael Uno
Quick & Easy
Common Ninja has a large selection of powerful Wordpress plugins that are easy to use, fully customizable, mobile-friendly and rich with features — so be sure to check them out!
Testimonial plugins for Wordpress
Galleries plugins for Wordpress
SEO plugins for Wordpress
Contact Form plugins for Wordpress
Forms plugins for Wordpress
Social Feeds plugins for Wordpress
Social Sharing plugins for Wordpress
Events Calendar plugins for Wordpress
Sliders plugins for Wordpress
Analytics plugins for Wordpress
Reviews plugins for Wordpress
Comments plugins for Wordpress
Portfolio plugins for Wordpress
Maps plugins for Wordpress
Security plugins for Wordpress
Translation plugins for Wordpress
Ads plugins for Wordpress
Video Player plugins for Wordpress
Music Player plugins for Wordpress
Backup plugins for Wordpress
Privacy plugins for Wordpress
Optimize plugins for Wordpress
Chat plugins for Wordpress
Countdown plugins for Wordpress
Email Marketing plugins for Wordpress
Tabs plugins for Wordpress
Membership plugins for Wordpress
popup plugins for Wordpress
SiteMap plugins for Wordpress
Payment plugins for Wordpress
Coming Soon plugins for Wordpress
Ecommerce plugins for Wordpress
Customer Support plugins for Wordpress
Inventory plugins for Wordpress
Video Player plugins for Wordpress
Testimonials plugins for Wordpress
Tabs plugins for Wordpress
Social Sharing plugins for Wordpress
Social Feeds plugins for Wordpress
Slider plugins for Wordpress
Reviews plugins for Wordpress
Portfolio plugins for Wordpress
Membership plugins for Wordpress
Forms plugins for Wordpress
Events Calendar plugins for Wordpress
Contact plugins for Wordpress
Comments plugins for Wordpress
Analytics plugins for Wordpress
Common Ninja Apps
Browse our extensive collection of compatible plugins, and easily embed them on any website, blog, online store, e-commerce platform, or site builder.
Show progress with animated progress circles that visualize goals, display achievements, and keep visitors engaged.
Create a mega footer that organizes navigation links, contact info, logos, social icons and improves usability and site structure.
Detect ad blockers on your site to maintain visibility into user behavior and support sustainable ad-based monetization.
Add an Instagram slider to your site to display social posts dynamically and keep your visual content engaging and current.
Create interactive diagrams with a diagrams widget that lets you build and customize flow charts, improve clarity, and help visitors understand complex ideas easily.
Capture email leads with an email subscription form that collects addresses, saves entries, sends notifications, and helps grow your audience.
Add a translation widget to your site so users can switch languages easily and access content in their preferred language.
Use an age verification popup to validate visitor age, meet regulatory requirements, and ensure only eligible users access restricted content.
Show posts in an X feed that keeps updates visible, improves content discovery, and helps visitors stay engaged with your latest activity.
Use a reviews badge to highlight your ratings, build trust at a glance, improve credibility, and help increase conversions across your site.
Use a timeline widget to display events and milestones in chronological order with images and text so visitors understand your story clearly.
Show Bluesky posts with a Bluesky feed that updates in real time, improves content discovery, and keeps visitors engaged with fresh activity.
More plugins
The Common Ninja Search Engine platform helps website builders find the best site widgets, apps, plugins, tools, add-ons, and extensions! Compatible with all major website building platforms - big or small - and updated regularly, our Search Engine tool provides you with the business tools your site needs!
