0

I'm using the enter_title_here filter to modify the 'Enter title here' text in a custom post type, question is what hook should I use to trigger this function?

I have used admin_enqueue_script as a test and it worked, but I think there is a better hook since this is not really a script.

    function print_scripts() { 
    $screen = get_current_screen();
    if ( 'post' === $screen->base && 'myposttype' === $screen->post_type ) {
        wp_enqueue_style( 'styles', WP_CSS . 'styles.css' );
        // filter used here
        add_filter( 'enter_title_here', function() { _e("Enter name here"); } );
    }  
    }

    add_action( 'admin_enqueue_scripts', 'print_scripts' );
  • You just need to call the filter enter_title_here. No action hook is required for that. Yes, for enqueuing the script, admin_enqueue_scripts will do. – Rutwick Gangurde Aug 22 '12 at 10:26
  • ok so it's all good like that. – urok93 Aug 23 '12 at 9:17
0

I believe it's a simple difference, here; you are echoing with e() - try returning with _() instead:

function custom_title_text( $title ){ return __( 'Enter Name here' ); } add_filter( 'enter_title_here', 'custom_title_text' );

  • I think I didn't explain myself very clearly the first time round, see edited question now please. I would like to know if I'm using the correct action hook or not. – urok93 Aug 22 '12 at 8:14
  • I can use the function you suggested, and then I would have to include those if statements (is there a better way to make that conditional?), and then fire that function on a hook, but which hook? admin_enqueue_scripts works, but is there a more appropriate hook for this? – urok93 Aug 22 '12 at 8:33
0

Answer was the one by @RutwickGangurde: You just need to call the filter enter_title_here. No action hook is required for that. Yes, for enqueuing the script, admin_enqueue_scripts will do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.