Hi there,
A friend of mine asked me how to add some text before and after post content in WordPress using Plugins.. it’s easy!
Let me tell you how:
function add_test_text($content) {
$content = “Before Content<hr>”.$content;
$content .= “<hr>After Content”;
return $content;
}add_filter( “the_content”, “add_test_text”,1 );
What we are doing here? let me explain line by line:
function add_test_text($content) {
We are just starting a function here with $content as the first (and only) variable.. Function name is “add_test_text”
$content = “Before Content<hr>”.$content;
What we are doing here is we are assigning “Before Content” as the value of the variable $content.
".$content;
this just adds (suffixes) the original $content variable after the string.
$content .= “<hr>After Content”;
If you notice there is a “.” (dot) before “=” (equals to sign), this DOT tells PHP that we want to add something after the variable.. rest is just like above.
return $content;
}