2

From my custom module I'd like to target essentially all front end pages on my site whether it be a node, front page, a views page or taxonomy page. I started out thinking it would be better to use logic that said if not admin or node edit / add but did not seem to have much luck. I came up with this and it seems to work fine but I don't know if accounts for every possible front end type of page that I have mentioned.

function mymodule_page_build(&$vars) {

  // Global node.
  $node = menu_get_object ();

  // Target front end pages
      if ((!empty($node) && arg(2) === null) || (drupal_is_front_page())) {

// do stuff

  }
}

I have a feeling the code does not account for all possible conditions I have mentioned so I am looking for some suggestions. I was thinking to exclude by path would be good except that node edit and node add don't have /admin in the url.

Note: By Target, I simply mean to focus or act upon. Example: If you want to add javascript or css to a specific page or pages from a module, you are "targeting" those pages.

  • What do you mean by "target"? You using this term from the beginning, but there is no such thing in Drupal per se, so could you add some explanation first? Or stick to the terms that are used in Drupal's documentation? – Mołot Feb 27 '14 at 14:46
  • By Target, I simply mean to focus or act upon. Example: If you want to add javascript or css to a specific page or pages from a module, you are "targeting" those pages. – Danny Englander Feb 27 '14 at 14:51
4

You can use the path_is_admin() function to determine whether or not a path is an admin page, so you can just use the reverse to determine if it's a non-admin page:

if (!path_is_admin(current_path())) {

}
| improve this answer | |
  • Exactly what I needed, thanks. It's weird that I've used that before but in reverse so it did not occur to me. – Danny Englander Feb 28 '14 at 0:58
  • There's one bracket missing. It must be if (!path_is_admin(current_path())) {} – leymannx Jun 21 '15 at 11:01
1

Are you using the same theme for admin pages and publicly viewable ones?

I've done this by using a separate admin theme - only the publicly viewable pages use my 'public' theme, so I can just show my 'public' stuff on all of them.

| improve this answer | |
  • I have no way of knowing what any given admin user will decide to do so that's why Clive's answer above is good as it is theme independent. – Danny Englander Feb 28 '14 at 1:00

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.