• Resolved rbergeron81

    (@rbergeron81)


    Hi, I am working on a site and the plugin works quite well in the normal content area of a post, but I am having trouble getting the icons to show up on content that is inside a tab or maybe it has something to do with the links being part of a custom field.

    You can see it here on the “Product Documents” tab at the bottom.

    https://clientdev10.dazil.com/?products=mi-5-multishot

    I am using advanced custom fields with the function:

    <?php echo get_post_meta(get_the_ID(), 'product_documents', true);?>

    to retrieve the field data which is a wysiwyg field. I have also tried using ACF’s API functions such as:

    <?php the_field('product_documents');?>

    Which didn’t work either.

    This is a custom theme with very few plugins installed.

    Any insight on this problem?

    https://www.ads-software.com/extend/plugins/mimetypes-link-icons/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hiya,

    Ok, as far as I can tell, the problem is quite simple: the plugin acts on the ‘the_content’ output of a post/page and you want it to act on other output.
    (This is presuming the <?php echo get_post_meta(get_the_ID(), 'product_documents', true);?> line is from your template file ? )

    You could try the plugin’s async option, but I doubt that will work as it looks like your theme also doesn’t use the normal class names, so the plugin still wouldn’t be able to get to your contents.

    AFAICS the easiest way to solve this would be to use a different method to add the tabs to the page.
    Instead of having the above mentioned line in your template file, try adding the following to your (child)theme’s functions.php:

    add_filter('the_content', 'add_my_tabs', 9);
    function add_my_tabs( $content ) {
    	return $content . get_post_meta(get_the_ID(), 'product_documents', true);
    }

    This should add the tabs to the_content before the MTLI plugin filters the_content for links and adds the icons.

    Hope this helps and please let me know whether this solved the issue for you.

    Smile,
    Juliette

    Thread Starter rbergeron81

    (@rbergeron81)

    That works sort of, but also returns the content from the post above the field content

    Here is the code I used

    <?php add_filter('the_content', 'add_tab_content', 9); ?>
    	<?php function add_tab_content( $content ) {
    	        return $content . get_post_meta(get_the_ID(), 'product_documents', true);
    	 }
    	?>
    <?php the_content();?>

    Eh… that’s sort of the point… you are filtering the_content, i.e. changing the original post (adding your tabs to it), so when you echo the_content it will contain the new altered content, in this case consisting of the original post + your tabs.

    Not sure whether you are familiar with hooks, filters and actions, so have a look/read here if you are not:
    https://codex.www.ads-software.com/Plugin_API and https://ottopress.com/2011/actions-and-filters-are-not-the-same-thing/

    Thread Starter rbergeron81

    (@rbergeron81)

    Ok, so I got it working

    I just removed $content from the return.

    Like this:

    <?php add_filter('the_content', 'add_tab_content', 9); ?>
        <?php function add_tab_content( $content ) {
    	return get_post_meta(get_the_ID(), 'product_documents', true);
         }
            ?>
    <?php the_content();?>

    Thanks for your help. Very much appreciated.

    Thread Starter rbergeron81

    (@rbergeron81)

    This is now resolved.

    You’re very welcome ??

    Looking at your final code and considering you don’t want the tabs to be output together with the_content, there is actually a neater way to do this – replace the complete snippet with the below:

    echo apply_filters( 'the_content', get_post_meta(get_the_ID(), 'product_documents', true) );

    This should have the same effect and should avoid some unnecessary overloading.

    Smile,
    Juliette

    Thread Starter rbergeron81

    (@rbergeron81)

    Yup, that works.

    Thanks again.

    @rbergeron81 the new version (v3) now contains an easier (and better) way to do this:

    mimetypes_to_icons( $yourcontent );

    so your code would become:

    echo mimetypes_to_icons( get_post_meta(get_the_ID(), 'product_documents', true) );

    For more info, have a look at the new FAQ.

    Hope this helps ??

    Smile,
    Juliette

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Not being added to links in tab’ is closed to new replies.