Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the Media Library Categories plugin. It does not have much documentation, so I have concluded the way to implement it would be using the shortcode [mediacategories categories="6"].

I want to implement this directly into the theme template. So I have tried:

<?php if(function_exists(do_shortcode('[mediacategories categories="6"]'))) { ?>
  <h1>Inspiration</h1>
<?php
  do_shortcode('[mediacategories categories="6"]');
}

I also tried to implement the function directly, but could not pass the $atts correctly for the function to use them.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

do_shortcode() just parses the string. You have to use echo or print to print it out.

function_exists() expects a string that matches a function name. After looking at the plugin, I would try this code:

<?php
if ( function_exists( 'mediacategories_func' ) )
{
?>
<h1>Inspiration</h1>
<?php
    print mediacategories_func( array( 'categories' => 6 ) );
}
share|improve this answer
add comment

I usually add a section like this to my shortcode callbacks:

if (is_array($atts)) {
    extract(shortcode_atts(array(
            'primary_att' => 'primary_default',
            ...
        ), $atts));
} else {
    $primary_att = $atts;
}

This enables you to pass a 'primary' attribute (replace primary_att with whatever you primary attribute is called) directly into the function, without wrapping it in an array...in your case it could be 'categories' and you could call it like mediacategories_func(6); then.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.