WordPress.org

Ready to get started?Download WordPress

Forums

is_singular() not working (3 posts)

  1. Naoise Golden Santos
    Member
    Posted 3 years ago #

    The problem is this simple: it doesn't work. The code is:

    /** custom post types */
    function create_post_type() {
      //projects
      register_post_type( 'project',
        array(
          'labels' => array(
            'name' => __( 'Projects' ),
            'singular_name' => __( 'Project' )
          ),
          'public' => true,
          'hierarchical' => true,
          'supports' => array('title','editor','thumbnail','custom-fields','page-attributes')
        )
      );
    }
    add_action( 'init', 'create_post_type' );
    
    /** scripts */
    function my_init_method() {
        if(is_singular('project')) {
            wp_deregister_script( 'jquery-topup' );
            wp_register_script( 'jquery-topup', 'http://gettopup.com/releases/latest/top_up-min.js');
            wp_enqueue_script( 'jquery-topup' );
        }
    }    
    
    add_action('init', 'my_init_method');

    When I render a single post of type project, the script is not called, whereas if I set the if(true) it does appear. Even the is_singular() doesn't render in single pages.

    Any known issue?

    Thank you

  2. vtxyzzy
    Member
    Posted 3 years ago #

    Wild guess: do you need to declare global $wpdb; in your function?

  3. Naoise Golden Santos
    Member
    Posted 3 years ago #

    didn't work. by declare you mean just putting $wpdb; somewhere right? also tried global $wpdb; but no.

    It's strange because ten lines down it does work, it may have to do with the add_action('init', 'my_init_method'); function...

    anyways, I ended up installing TopUp Plus plugin that got that part of the job done.

    Thank you

Topic Closed

This topic has been closed to new replies.

About this Topic