WordPress Gallery [short codes] and custom fields

As a follow up to my recent post on custom fields I ran into another issue revolved around plugins or the built in WordPress gallery codes not working in custom fields.

Since those codes only work inside the post/page’s content a filter needs to be applied.

Nothing has changed the setup:

ID, 'slideshow', true); ?>

and instead of,

<? php echo $image; ?>
[/sourcecode ]
we'll apply the filter,
[sourcecode language='php']
<? php
$img = ''.$image.'';
$img = apply_filters('the_content', $img );
echo $img;
?>;

This could help in appending your custom fields too, for example you could setup the custom field for a code input only and wrap the value. Example,
[sourcecode language='php']
$id = ””;
$id = apply_filters(‘the_content’, $id );
echo $id;
[/sourcecode ]
A value “3″ would create ““.

props to the WP forums

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 »

  • Tom
    Thnx for the post, useful stuff.
blog comments powered by Disqus