• Hi all,

    I need to add a very simple custom function to my template, which will receive a variable and then churn out some HTML automatically. But I don’t know where to put it (still new to WP): does it go into the function.php of my theme folder, or do I need to write a plugin, or is it something else entirely?

    What I need to do is to be able to write inside a post something like <? my_function(parameter); ?> and then have the HTML added at that place in the post. Is it even possible in WP (I mean, adding some PHP inside post text)?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You can create a plugin if you want, but there are many php plugins out there like:

    Exec-PHP – http://soeren-weber.net/post/2005/08/18/50/

    PHP-Exec – http://priyadi.net/archives/2005/03/02/wordpress-php-exec-plugin/

    RunPHP – http://www.nosq.com/2004/10/runphp-wordpress-plugin

    All those plugins are listed in the codex.

    http://codex.wordpress.org/Plugins/Posts_Formatting

    Thanks,

    Trent

    Thread Starter talino

    (@talino)

    Thanks a lot, now I see that I need a plugin to run PHP from within a post. But still, where do I write my function? Is my theme’s functions.php a good place?

    Thanks a lot.

    It would depend on what you are adding, but it could be anywhere you want. I run php scripts in my site that are just uploaded into a directory in my wp-content folder.

    I would try and place the function you are writing in something that isn’t a core file so that you don’t have to keep updating it as the version changes.

    Simple question, what is the function about? Does it involve any other WordPress file or is it standalone?

    Trent

    talino, your active theme’s functions.php is typically a good place for your own functions, if you’re not up to creating a plugin. But keep in mind functions in that file will not work between themes.

    Thread Starter talino

    (@talino)

    Not working across themes is indeed a problem, but I don’t see what I can do about it aside from writing a plugin (which I don’t know how to do, I tried reading about it and got totally confused).

    The function is a very simple one, a kind of mini gallery. I want to be able to add it between two paragraphs, and it should scan a specified folder and spit out formatted divs & tags based on my folder structure and links. This is so that the mini gallery is automatically updated when I simply upload a new image.

    For an example on how this looks: http://www.talino.org/photography/fishermen/

    I simply want to write this in a post:

    blah blah
    <? gallery_here('blah'); ?>
    more blah

    and have it create this dynamically :

    blah blah
    <div class="thumbnail"><a href="/images/blah/01.jpg" rel="lightbox[blah]"><img src="/images/blah/thumbs/01.jpg"/></a></div>
    <div class="thumbnail"><a href="/images/blah/02.jpg" rel="lightbox[blah]"><img src="/images/blah/thumbs/02.jpg"/></a></div>
    more blah

    etc, a div for each image in the folder.

    I know how to write this function but I simply don’t know where 🙂

    Thanks for all your help.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Custom functions’ is closed to new replies.