WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] is_single problem! (5 posts)

  1. gxt
    Member
    Posted 1 year ago #

    Hi,
    I'm having problems with is_single()

    The problem is that is_single() is supposed to work only on posts, NO "pages" and "attachments", if I understand it right. Because if not there will be no difference between is_single and is_singular

    is_single() returns true if any single post is being displayed
    is_singular() returns true when any page, attachment, or single post is being displayed.

    But If I try to include a file only into a POST

    <?php if ( is_single() ) { ?>
    	<link rel="stylesheet" href="style.css" />
    <?php } ?>

    the css file appears also on attachment pages
    example.com/?attachment=123456789 AND THAT AINT SUPPOSED TO HAPPEN.

    Is there a bug in wordpress or I'm doing something wrong?!!

    Thank you!

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Are your attachments pointing to POST pages when you insert them?

  3. gxt
    Member
    Posted 1 year ago #

    when I insert images I use
    [gallery columns="1" size="large"]
    then in the post, images (somename-500x550.jpg) point to the original image (somename.jpg) not to the attachment page.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    Can we see one of these attachment links & pages?

  5. gxt
    Member
    Posted 1 year ago #

    it's not online yet. But problem was solved
    - 2 ways to exclude attachments from POSTS and get a file only and exclusively on POSTS.
    - 1:

    <?php if ( is_single() && !is_attachment() ) { ?>
        <link rel="stylesheet" href="style.css" />
    <?php } ?>

    - 2 way:

    <?php if ( is_singular('post') ) { ?>
        <link rel="stylesheet" href="style.css" />
    <?php } ?>

    I suggest the second way.

    -
    Thanks to wordpress.stackexchange for the help

Topic Closed

This topic has been closed to new replies.

About this Topic