1

when Yoast plugin is enabled shortcodes not working in category or tag description

I used this and this article and add these codes to the function but nothing change please help me.

add_filter( ‘term_description’, ‘do_shortcode’ );
add_filter( ‘category_description’, ‘do_shortcode’ );
add_filter( ‘post_tag_description’, ‘do_shortcode’ );


function my_shortcode()
{
    ob_start();
    require_once(get_template_directory() . '/html/htmlcontent.php');
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}
add_shortcode("shortcode","my_shortcode");

Update: When I use the below code everything fine. I don't know whats the problem

function my_shortcode() {
    $url = get_template_directory() . '/html/my_shortcode.php';
    $content = file_get_contents($url);
    return $content;
}
3
  • Does this answer your question? shortcode not working Mar 31, 2020 at 21:50
  • @Farukrıza no. I think my shortcode function has a problem
    – D.JCode
    Mar 31, 2020 at 22:07
  • 1
    You don't actually use the in your code, do you? But even if you don't, you should change it to ' in the question.
    – Sally CJ
    Mar 31, 2020 at 22:53

1 Answer 1

0

You entered the quotation marks wrong, I fixed it, maybe it will help:

add_filter( 'term_description', 'do_shortcode' );
add_filter( 'category_description', 'do_shortcode' );
add_filter( 'post_tag_description', 'do_shortcode' );

function my_shortcode()
{
    ob_start();
    require_once(get_template_directory() . '/html/htmlcontent.php');
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}
add_shortcode("shortcode","my_shortcode");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.