Looking for a simple solution that will allow you to insert a script such as Google Adsense ad or HTML in the Body field of a content type.
The insert can be after the first five paragraph tags in the Body field. Or maybe in the middle of content.
While on WordPress there were a lot of plugins to do this, in Drupal I can’t find a solution. There are blocks, but you can’t inject them in the middle of content.
Any help is greatly appreciated.
Tried this in as a module but can’t get it to work.
<?php function adinject_node_view(array &$ build, \Drupal\Core\Entity\EntityInterface $ entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $ display, $ view_mode) { if ($ entity->getType() == 'vehicle_repair_guides' && $ view_mode == 'full') { $ pieces = explode('<p>', $ build['body'][0]['#text']); $ new_text = ''; foreach ($ pieces as $ key => $ value) { $ new_text .= '<p>' . $ value; if ($ key == 2) { $ new_text .= '<p>AD GOES HERE!</p>'; } } $ build['body'][0]['#text'] = $ new_text; } }