1

I want to display a custom widget in my custom plugin ONLY on post pages. How can I do this without using a third party plugin or editing the theme files?

is_single() does not work in the widget method of the Widget class.

1
  • 2
    Why doesn’t is_single work? Could you show the code of that widget and do you use any custom loops at single post template? Commented Mar 14, 2019 at 5:25

1 Answer 1

0

Display your widget only on post pages by adding if ( !is_single() or is_page()) { return;} at the start of your Widget's function widget()

public function widget( $args, $instance ) {
    if ( !is_single() or is_page()) {  return;}

    // rest of code
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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