WordPress.org

Make WordPress Core

Opened 11 days ago

Closed 11 days ago

Last modified 11 days ago

#52537 closed defect (bug) (invalid)

is_single is_singular is not working

Reported by: BackuPs Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

Hi

i have a weird issue. If i use a clean install and add code like this in the functions.php of f.e. the 20-21 theme and go to the single post page in the front end that echo does not happen.

I am using the latest beta version of wordpress 5.7 and php 8.0

any idea why this is not happening?

if (is_singular( 'post' )) echo '---------------------------> this is a post';

if (is_single()) echo '---------------------------> this is a post';

if i add it without checking

echo '---------------------------> this is a post';

The text of course shows.

What is going on that this does not work in the functions.php on a single post page?

I tried any defaul wp theme and premium theme and they all have the same problem.

Attachments (2)

single-code-added.jpg (88.3 KB) - added by BackuPs 11 days ago.
code added at the bottom of the functions.php
single-post-no-text.jpg (185.7 KB) - added by BackuPs 11 days ago.
see single post page

Download all attachments as: .zip

Change History (4)

@BackuPs
11 days ago

code added at the bottom of the functions.php

@BackuPs
11 days ago

see single post page

#1 @audrasjb
11 days ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version trunk deleted

Hi @BackuPs,

Looks like this is a support question (in which context is_single/is_singular function can be used) rather than a bug/enhancement report. I'd suggest to ask in WordPress support forums instead: https://wordpress.org/support/forum/wp-advanced/

Thanks for your comprehension

#2 @audrasjb
11 days ago

By the way, these conditional tags must be used inside the loop, and functions.php is called before the loop.

Try add_action( 'wp_body_open', function() { var_dump( is_single() ); } );.

However, please avoid to open Trac tickets for support questions ;)

Last edited 11 days ago by audrasjb (previous) (diff)
Note: See TracTickets for help on using tickets.