do stuff if is custom post type, on admin view (3 posts)

  1. hilj
    Posted 4 years ago #


    I'm looking into editing the backend, and would like to have a date picker for the title field, but only for custom post type called recommendations.

    I'm loading an extra js file to do it (from functions.php), but can't target the recommendations post type.

    This isn't working:

    function customAdminJavascript() {
      $admin_script_url = get_settings('siteurl');
      $admin_script_url = get_stylesheet_directory_uri() . '/js/admin-script.js';
      echo '<!-- custom admin javascript -->
              <script src="' . $admin_script_url . '"></script>
            <!--/custom admin javascript -->';
    //Try to spew it out in the header only when editing/writing a recommendation
    if ('recommendations' == get_post_type()) {
      add_action('admin_head', 'customAdminJavascript');

    What sort of conditional statement I should use?

    Thanks for all the help :)

  2. hilj
    Posted 4 years ago #

    Sorry for bumping so early but anybody have a glue? Cheers.

  3. hilj
    Posted 4 years ago #

    Found an answer to this, with one drawback, it does not effect when editing the custom post type. It's good when viewing the custom post type archive page and when creating a new page.

    if ((isset($_GET['post_type']) && $_GET['post_type'] == 'recommendations') || (isset($post_type) && $post_type == 'recommendations')){
      //do stuff

    Can anybody help? Thanks :)

Topic Closed

This topic has been closed to new replies.

About this Topic