Plugin woes

I’m having the hardest time trying to figure out how to add an onload to the body tag to wordpress. I’m making a plugin and hopefully I’ll find the hook or tag I need to do it soon, otherwise I’m going to go mad. I’ve already built the plugin with a full admin page–something totally new to me–and what seems like the easiest piece is giving me the hardest time.

About the Author, Dan Cameron:

I'm the owner and solution engineer at Sprout Venture, a web solutions company that specializes in web development including WordPress.

I started my first blog in 2003 and transitioned to WordPress in 2004. Since moving to WordPress I've written a few plugins and themes for public consumption. Lately I'm busy engineering/building/coding and have only been able to share a few code snippets.

If you're in need of some web development, web design or custom WordPress plugins and/or themes contact me, I'll be happy to discuss it with you.

Read More »

  • BillyG
    IRT the dot scenario, I have that problem all the time when uploading software to my domain that is hosted by Y! (don't bother).

    Anything with a dot in the name (coincidentally including all OSX related directories) does not get uploaded, something authors definitely need to be aware of!
  • Yeah, I think I need to repackage those plugins. I'll probably just use zip instead of .tar.gz, as those seem to be more problematic.

    The way I'm doing mine is in the plugin (in that add to head section) I'm adding a link to a seperate javascript file, which then contains some code (down at the bottom) that ads a function to the window.onload. If you don't want to have a seperate .js file, though, you can also just add script instead of a file reference like I'm doing.

    Also, prototype has fancier / simpler event handling code, which would probably be even better to use since it's there. You can do something like Event.observe(window, 'load', your_init_function);
  • Dan
    I'll try to figure it out later but I looked at your code and it I didn't see anything with window.onload or anything that would do the same thing. I did see the part for "add to head" but I'm missing something. I'll find it though when I have time tomorrow, otherwise you can just email or post it here.
    A problem I might have is theme compatibility because I can't just replace the body tag I need to add to it.
  • Dan
    Perfect thanks. BTW, your plugin extracts to a folder prefixed with a dot .fr... so it no shows in OSX and I'd assume some distros.
  • Oops, commented on the other post first... you can try checking my Sidebar Collapser plugin for the method I was describing. I'm using window.onload, but you can use body or whatever, and you should be able to do it just from your plugin (no extra theme mods). E-mail me if you want more info.
blog comments powered by Disqus