Difference between revisions of "WordPress Comments within Page or Post Body"

Wiki.TerraBase.info
Jump to navigation Jump to search
m
m
Line 3: Line 3:
Programmers have this capability to add such notes within their program without affecting the software.  Examples of comments are below in terms of how these comments are inserted;
Programmers have this capability to add such notes within their program without affecting the software.  Examples of comments are below in terms of how these comments are inserted;


* In many forms of BASIC: REM Anything after an REM command is a comment
*In many forms of BASIC: REM Anything after an REM command is a comment
* HTML: <--  Anything in between the <-- (less than symbol and two dashes / hyphens) and --> (two dashes / hyphens and a greater than symbol) is a comment -->
*HTML: <--  Anything in between the <-- (less than symbol and two dashes / hyphens) and --> (two dashes / hyphens and a greater than symbol) is a comment -->
* Java: /* Anything in between /* (forward slash and asterisk) and */ (asterisk and forward slash) is a comment */
*Java: /* Anything in between /* (forward slash and asterisk) and */ (asterisk and forward slash) is a comment */
* ...and about a billion other examples: https://en.wikipedia.org/wiki/Comment_(computer_programming)
*...and about a billion other examples: https://en.wikipedia.org/wiki/Comment_(computer_programming)


Does WordPress have such a method to do this?  Nope.
== Question(s) ==
Does WordPress have such a method to do this as a built in function or method?  Nope.


Should it?  Many think so.
Should it?  Many think so.
Line 14: Line 15:
Is there a plugin for this?  Not as of the end of 2020*  *Notice that asterisk there...  When searching for such a plugin, there are plugins that offer a "comment / comments" shortcode that can be inserted into the body of a post or page.  But the catch is that those "comment / comments" shortcodes are for the a fore mentioned "comments" that are messages / feedback from readers.  Not at all what is needed.
Is there a plugin for this?  Not as of the end of 2020*  *Notice that asterisk there...  When searching for such a plugin, there are plugins that offer a "comment / comments" shortcode that can be inserted into the body of a post or page.  But the catch is that those "comment / comments" shortcodes are for the a fore mentioned "comments" that are messages / feedback from readers.  Not at all what is needed.


Is there a solution?  Yup.  And it is described below.  Full credit on the ideabecause the answer is sourced from here: https://wordpress.stackexchange.com/questions/346286/is-it-possible-to-comment-out-text-in-a-post?rq=1
Is there a solution?  Yup.  And it is described below.  Full credit on the idea because the answer presented here is sourced from this nice person: https://wordpress.stackexchange.com/questions/346286/is-it-possible-to-comment-out-text-in-a-post?rq=1


== Solution ==
==Solution==


=== Objective ===
===Objective===
Add the capability to include comments within a page or post using simple shortcode that is equivalent to other commenting methods in programming languages such as HTML, Java, etc.
Add the capability to include comments within a page or post using simple shortcode that is equivalent to other commenting methods in programming languages such as HTML, Java, etc.


=== End Solution ===
===End Solution===
[Comment]Anything in between these shortcode items is not displayed to end readers or even include in the HTML output to a browser (IE, it is stripped out at the server level) [/Comment]
[Comment]Anything in between these "comment" shortcode items is not displayed to end readers or even include in the HTML output to a browser (IE, it is stripped out at the server level) [/Comment]


=== How it is Implemented ===
===How it is Implemented===
Within the theme's ''function.php'' file (or the child theme's equivalent file) add this simple line of code: <code>add_shortcode( 'comment', '__return_empty_string' );</code>
Within the theme's ''function.php'' file (or the child theme's equivalent file) add this simple line of code: <code>add_shortcode( 'Comment', '__return_empty_string' );</code>


One can also address any confusion about upper / lower case (since Linux is case sensitive) or plural or non-plural by including the following;<syntaxhighlight lang="text">
add_shortcode( 'comment', '__return_empty_string' );
add_shortcode( 'Comment', '__return_empty_string' );
add_shortcode( 'COMMENT', '__return_empty_string' );
add_shortcode( 'comments', '__return_empty_string' );
add_shortcode( 'Comments', '__return_empty_string' );
add_shortcode( 'COMMENTS', '__return_empty_string' );
</syntaxhighlight>...done, that's it.


== Alternate Solution ==
Another suggestion is sourced from here: https://stackoverflow.com/questions/3344270/is-it-possible-to-comment-out-html-code-in-a-wordpress-post and suggests a method to enable using HTML comment tags within a page or post.
Another suggestion is sourced from here: https://stackoverflow.com/questions/3344270/is-it-possible-to-comment-out-html-code-in-a-wordpress-post and suggests a method to enable using HTML comment tags within a page or post.

Revision as of 11:02, 6 January 2021

This article is about creating the capability of placing comments within the body of a page or post for WordPress. To be very clear, the "comment / comments" referred to here are not messages (AKA comments) from readers often viewed as "feedback". The "comments" referred to here are comments in the sense / context of "notes to self" within the body of a page or post.

Programmers have this capability to add such notes within their program without affecting the software. Examples of comments are below in terms of how these comments are inserted;

  • In many forms of BASIC: REM Anything after an REM command is a comment
  • HTML: <-- Anything in between the <-- (less than symbol and two dashes / hyphens) and --> (two dashes / hyphens and a greater than symbol) is a comment -->
  • Java: /* Anything in between /* (forward slash and asterisk) and */ (asterisk and forward slash) is a comment */
  • ...and about a billion other examples: https://en.wikipedia.org/wiki/Comment_(computer_programming)

Question(s)

Does WordPress have such a method to do this as a built in function or method? Nope.

Should it? Many think so.

Is there a plugin for this? Not as of the end of 2020* *Notice that asterisk there... When searching for such a plugin, there are plugins that offer a "comment / comments" shortcode that can be inserted into the body of a post or page. But the catch is that those "comment / comments" shortcodes are for the a fore mentioned "comments" that are messages / feedback from readers. Not at all what is needed.

Is there a solution? Yup. And it is described below. Full credit on the idea because the answer presented here is sourced from this nice person: https://wordpress.stackexchange.com/questions/346286/is-it-possible-to-comment-out-text-in-a-post?rq=1

Solution

Objective

Add the capability to include comments within a page or post using simple shortcode that is equivalent to other commenting methods in programming languages such as HTML, Java, etc.

End Solution

[Comment]Anything in between these "comment" shortcode items is not displayed to end readers or even include in the HTML output to a browser (IE, it is stripped out at the server level) [/Comment]

How it is Implemented

Within the theme's function.php file (or the child theme's equivalent file) add this simple line of code: add_shortcode( 'Comment', '__return_empty_string' );

One can also address any confusion about upper / lower case (since Linux is case sensitive) or plural or non-plural by including the following;

add_shortcode( 'comment', '__return_empty_string' );
add_shortcode( 'Comment', '__return_empty_string' );
add_shortcode( 'COMMENT', '__return_empty_string' );
add_shortcode( 'comments', '__return_empty_string' );
add_shortcode( 'Comments', '__return_empty_string' );
add_shortcode( 'COMMENTS', '__return_empty_string' );

...done, that's it.

Alternate Solution

Another suggestion is sourced from here: https://stackoverflow.com/questions/3344270/is-it-possible-to-comment-out-html-code-in-a-wordpress-post and suggests a method to enable using HTML comment tags within a page or post.