Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#52537 closed defect (bug) (invalid)

is_single is_singular is not working

Reported by: backups's profile 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 4 years ago.
code added at the bottom of the functions.php
single-post-no-text.jpg (185.7 KB) - added by BackuPs 4 years ago.
see single post page

Download all attachments as: .zip

Change History (4)

@BackuPs
4 years ago

code added at the bottom of the functions.php

@BackuPs
4 years ago

see single post page

#1 @audrasjb
4 years 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
4 years 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 4 years ago by audrasjb (previous) (diff)
Note: See TracTickets for help on using tickets.