- This topic has 12 replies, 3 voices, and was last updated 6 years, 10 months ago by Leo.
-
AuthorPosts
-
November 3, 2017 at 3:04 am #415425Surya
Hi,
I have a website with short code for google maps in all the posts.
However, I need to stop the short code from showing in posts listed under specific category.
Category ID : 1
Category name : USA Attorneys
Category slug : usa-attorneysCan you please suggest a conditional command to strip the shortcodes from the posts listed under USA Attorneys from displaying while retaining the short codes in posts.
I tried the code
function remove_shortcodes( $content ) {
if ( is_category(1) ) {
$content = strip_shortcodes( $content );
}
return $content;
}
add_filter( ‘the_content’, ‘remove_shortcodes’ );but, no use.
May please advise.
November 3, 2017 at 8:56 am #415648LeoStaffCustomer SupportHi there,
Hmm you can use
!
to exclude a certain category when you are adding code initially:
if ( ! is_singular ( 'usa-attorneys' ) && ! in_category ( 'usa-attorneys' ) )
November 3, 2017 at 9:33 am #415678SuryaHi,
I inserted the following code in functions.php, but does not change anything.
function remove_shortcodes( $content ) {
if ( ! is_singular ( ‘usa-attorneys’ ) && ! in_category ( ‘usa-attorneys’ ) ) {
$content = strip_shortcodes( $content );
}
return $content;
}
add_filter( ‘the_content’, ‘remove_shortcodes’ );November 3, 2017 at 12:05 pm #415769LeoStaffCustomer SupportYou shouldn’t have to remove it – just don’t add it in to that category to start with.
How and where are you adding the shortcode currently?
November 4, 2017 at 6:53 pm #416381SuryaHi,
I have already created a number of posts with shortcodes for Google maps under this category.
Now, I am trying to strip the shortcodes from the posts belonging to this specific category.
I was able to successfully strip shortcodes from archive pages like index, categories & tags with the code I have mentioned in the first thread but not in the posts belonging to a specific category.
November 4, 2017 at 10:04 pm #416434TomLead DeveloperLead DeveloperInstead of
is_category(1)
, tryin_category(1)
.November 5, 2017 at 9:06 am #416590SuryaHi,
It’s not working.
November 5, 2017 at 9:43 am #416612TomLead DeveloperLead DeveloperCan you show me your exact code?
November 5, 2017 at 10:52 am #416644SuryaHi,
The sample short code is
[flexiblemap address=”711 Gaffney Rd Suite 202, Fairbanks, AK-99701″ title=”Zimmerman & Wallace Attorneys At Law” description=”Estate Planning Attorney, Personal Injury Lawyer, Real Estate Attorney” width=”100%” directions=”true”]
November 5, 2017 at 4:19 pm #416767LeoStaffCustomer SupportCan you show us the full code? not just the short code part.
Thanks!
November 9, 2017 at 8:29 am #419683LeoStaffCustomer SupportI don’t see the part where you used
in_category(1)
as Tom suggested?Also please reply here. Thanks!
November 11, 2017 at 9:20 am #421787SuryaHi,
I added the below code in the beginning of single.php before header and got the desired result of stripping short codes from posts in category id 1.
function remove_shortcodes( $content ) { if ( in_category(1) ) { $content = strip_shortcodes( $content ); } return $content; } add_filter( ‘the_content’, ‘remove_shortcodes’ ); The entire single.php is as below. <?php /** * The Template for displaying all single posts. * * @package GeneratePress */ function remove_shortcodes( $content ) { if ( in_category(1) ) { $content = strip_shortcodes( $content ); } return $content; } add_filter( 'the_content', 'remove_shortcodes' ); get_header(); ?> <div>> <main id="main" <?php generate_main_class(); ?>> <?php do_action('generate_before_main_content'); ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', 'single' ); ?> <?php // If comments are open or we have at least one comment, load up the comment template if ( comments_open() || '0' != get_comments_number() ) : ?> <div class="comments-area"> <?php comments_template(); ?> </div> <?php endif; ?> <?php endwhile; // end of the loop. ?> <?php do_action('generate_after_main_content'); ?> </main><!-- #main --> </div><!-- #primary --> <?php do_action('generate_sidebars'); get_footer();
Is this okay?
Thanks & Regards,
Surya
November 11, 2017 at 12:46 pm #421909LeoStaffCustomer SupportYup if it works then it should be good!
-
AuthorPosts
- You must be logged in to reply to this topic.