When typing on a blog post, I would like to insert code for Adsense or another code using a short-name that references the code rather than pasting the code directly into my blog post. Is there an easy way to do this?

For example, I would like to define a short-name like this:

"dogphoto" = "<img src="http://www.news.cornell.edu/stories/Sept05/dog.jpg" />"

Then I could merely reference the short-name for the code by typing this:

"I love dogs. I love all dogs. Here is a photo of a Dog. {dogphoto}. Isn't that dog cute?"

The resulting HTML would be this:

"I love dogs. I love all dogs. Here is a photo of a Dog. <img src="http://www.news.cornell.edu/stories/Sept05/dog.jpg" />. Isn't that dog cute?"

I presume this could be done by including a text file. A Wordpress plugin (MiniManager) does this by allowing users to "name" a mini-block of code and then call that code in the blog post by referencing it.

Is there a way to do this in Drupal? If so, it would be a time-saver for repetitive blocks of code that need to be entered when writing a blog post or page. It could be used to insert Adsense ads, Yahoo Ads, a disclaimer at the end of the post, etc.

Thanks in advance for any suggestions.

Comments

paintballguns’s picture

Here is a complex way to partly accomplish this task. These instructions place Adsense code (or any code) after the first paragraph of a blog post. See http://www.alldrupalthemes.com/blog/automagically-placing-adsense-inside....

Unfortunately, these instructions don't give the writer control over where the code is inserted. Also, these instructions require modifying Drupal files, which is scary for a newbie.

Any other ideas?

paintballguns’s picture

I found this suggestion online. Would this work?

Sidebar blocks contain all sorts of nifty stuff, but sometimes you want to stick that stuff into the body of your node. Instead of using PHP snippets (a possible security hole on public sites), you can use this module. When it's activated...

[block:name of module=delta of block]

...will insert the contents of a rendered sidebar block into the body of your node. If no delta is specified, the default block for that module will be displayed.

The problem with this is it only displays a sidebar block that is already rendered on the page.

Another option would be putting the Adsense code into a block, and then calling the block from within the blog post as described here: http://drupal.org/node/26502. Would this work?

paintballguns’s picture

None of these options seem to work. Does anyone have any other ideas?

paintballguns’s picture

If I can't get this resolved, I'll have to give up on Drupal.

paintballguns’s picture

A Drupal expert at http://www.drupal4seo.com/ tells me that the solution referenced above (inserting the block into the content) will work. But she said that in order for it to work, you do have to activate it under 'input format' and then select that option on the content page.

paintballguns’s picture

Here is another relevant tip: "Insert Block into Content" at http://drupal.org/node/161443.