-2

I need to place this code inside a function within functions.php

How do I go about doing this?

EDIT: This is in regards to an answer I received about a problem with Headers.

"isn't inside a function. So it's being called as soon as the file loads. This means all output is sent to the screen immediately This stuff should be inside a function which is then called at the right time (like the other bits)."

The problem is, I don't know how to put this code inside a function.

    add_shortcode("snap", "wpr_snap");
$user_ej = wp_get_current_user();
if ($user_ej->roles[0] == 'contributor')
{ ?>
  <style type="text/css">
    #menu-dashboard, #toplevel_page_wpcf7, #menu-tools 
    {
        display:none;
    }
</style>
<?php }
add_filter(  'gettext',  'change_post_to_portfolio'  );
add_filter(  'ngettext',  'change_post_to_portfolio'  );
  • Could you better explain what you mean by "place this code inside a function within functions.php", why can't you just do it? – C. E. Oct 21 '12 at 11:28
  • This code was in the functions.php. But it was causing an error that I explained here: http://stackoverflow.com/questions/12989589/cannot-modify-header-information-headers-already-sent-in-wordpress. The answer is to ensure that the code above is 'put inside a function'. But I don't know how to do that. – user1761675 Oct 23 '12 at 08:40
  • I advise you to study PHP and Wordpress some more. You seem to be in a little bit above your head. (I'm saying this for your own good and not to be mean. It would be easier to ask good question if you knew a bit more. I tried to answer the question here below as well as I could.) – C. E. Oct 23 '12 at 11:07
  • Legend!! You solved it completely. Agree that I'm in over my head and thanks to people like you, I can get by in the deep end. I see what you did, and I think I have learned from it. Many thanks – user1761675 Oct 23 '12 at 13:34

1 Answers1

0

Based on the content of your code you should probably rewrite it like this:

    add_shortcode("snap", "wpr_snap");
function add_extra_css() {
$user_ej = wp_get_current_user();
if ($user_ej->roles[0] == 'contributor')
{ ?>
  <style type="text/css">
    #menu-dashboard, #toplevel_page_wpcf7, #menu-tools 
    {
        display:none;
    }
</style>
<?php }
}
}
add_action( 'wp_head', 'add_extra_css' );
add_filter(  'gettext',  'change_post_to_portfolio'  );
add_filter(  'ngettext',  'change_post_to_portfolio'  );
C. E.
  • 10,297
  • 10
  • 53
  • 77