How to alter text filters conditionally based on content type? How can I get the content type of the current node from within a text filter, so I can use it to conditionally alter how the filter is applied?

Getting the node ID from the arg() function and using it to load a node object does not work because the text filter is run multiple (30+) times and exhausts the available memory.

$node = menu_get_object();
if ( !empty($node) ) {
  dd('Have a node, do something');
}


The same is true with the following method of getting the content type: $node = menu_get_object();
You could go with the following code inside your filter's callback function:

if(arg(0) == 'node' &amp;&amp; arg(1) &gt; 0){
  $result = db_select('node', 'n')
  -&gt;fields('n', array('type'))
  -&gt;condition('nid', arg(1),'=')
  -&gt;execute()
  -&gt;fetchAssoc();
  dsm($result['type']);
}


Good luck!