I have specific text (including shortcodes) I would like to display after the content in posts of a particular category – including the subcategories of the main category.
In the WordPress editor I enter the following:
[hide_from level="subscriber"]
This content is exclusively for Corner Office Members. If you are a Member please Log In.
Not a Member? Please Consider becoming a member for ONLY $18/yr. Membership supports the site and gives users access to many exclusive resources not available to non-members, as well as substantial discounts on store merchandise.
Exclusive in-depth content ONLY for subscribers!
Large color screenshots illustrate the instructions!
Email notification of each new post to the Member’s Area!
Exclusive discounts on books and other products!
[add_to_cart item="1" ajax="yes" ]
[/hide_from]
I would like to automate this by adding it to the functions.php of the theme. I played with it a bit, but my PHP is extremely rusty. Below is the code I have, which doesn’t work. Can you fix it so I can add it to the functions.php file and have it add the above text/html/shortcodes to all posts in a category and all sub-categories of the main category?
/ Adds text at bottom of Paid posts - DSH /
add_filter('the_content', 'custom_category_text');
function custom_category_text($content){
global $post;
$custom_category_text = echo do_shortcode('[hide_from level="subscriber"]');
echo "<p><span style="color: #ff0000;"><strong>This content is exclusively for Carol's Corner Office Members.</strong></span> <strong>If you are a Member please <a href="http://www.my-website.com/member-login/" target="self">Log In</a>.</strong></p>
<p>Not a Member? Please Consider <a href="http://www.MYWEBSITE HERE.com" target="self">becoming a member for ONLY $18/yr</a>. Membership supports the site and gives users access to many exclusive resources not available to non-members, as well as substantial discounts on store merchandise.
<ul>
<li>Exclusive in-depth content ONLY for subscribers!</li>
<li>Large color screenshots illustrate the instructions!</li>
<li>Email notification of each new post to the Member’s Area!</li>
<li>Exclusive discounts on books and other products!</li>
</ul></p>";
echo do_shortcode('[add_to_cart item="1" ajax="yes"]');
echo do_shortcode('[hide_from"]');
if(in_category('28')){ // change catetegory ID
$content = $content . $custom_category_text;
}
return $content;
}
Please help me out, I've got a deadline and am currently at a loss.