0

I use this function to assign the title of every page:

function my_title() {
    switch ( true ) {
        // [...]
        case (is_attachment()):
            wp_title(''); // This doesn't work
            break;
        default :
            wp_title(''); // This works
    }
}
add_filter( 'wp_title', 'my_title', 10, 2 );

It seems the conditional is_attachment() is not working in this case, but it works when it returns the default value. When I say «it's not working» I mean it's not loading the page, it just prints «waiting localhost». At the end it shows:

Unable to load the webpage because the server sent no data. Error code: ERR_EMPT

Why is that?

In the header.php file I have this code:

<title><?php wp_title(''); ?></title>

Any suggestion? I don't know if the problem is the conditional tag, the switch, the filter or the wp_title() function. Ah, and I use it into a large function:

add_action( 'after_setup_theme', 'theme_functions', 2);

UPDATE: LOL, I think I found my mistake. I was using the wp_title() function when I had to use the_title() into the attachment case. I guess I created a bucle...

  • If you have a solution, submit your solution and mark it as such. – mor7ifer Jan 29 '15 at 15:35
  • @m0r7if3r, yes. Actually, I just updated the post. I think I created a bucle. Could you confirm if that was my mistake? Thanks in advance. – Gerard Jan 29 '15 at 15:36
  • I'm not running your code, only you can confirm that a solution worked for you. – mor7ifer Jan 29 '15 at 15:42
  • Yep, I think it's ok because it returns the image title attribute. Thanks anyway ;) – Gerard Jan 29 '15 at 15:49

Your Answer

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

Browse other questions tagged or ask your own question.