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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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 ) );
}
Method 2
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0