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

Wiki.TerraBase.info
Jump to navigation Jump to search
(Created page with "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...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
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.
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: <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.
Again, thank you to this individual for posting the above mentioned source of this article: https://wordpress.stackexchange.com/users/20143/phatskat
==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.

Latest revision as of 11:21, 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.

Again, thank you to this individual for posting the above mentioned source of this article: https://wordpress.stackexchange.com/users/20143/phatskat

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.