WordPress.org

Ready to get started?Download WordPress

Forums

MimeTypes Link Icons
[resolved] Not being added to links in tab (9 posts)

  1. rbergeron81
    Member
    Posted 1 year ago #

    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.

    http://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?

    http://wordpress.org/extend/plugins/mimetypes-link-icons/

  2. jrf
    Member
    Plugin Contributor

    Posted 1 year ago #

    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

  3. rbergeron81
    Member
    Posted 1 year ago #

    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();?>
  4. jrf
    Member
    Plugin Contributor

    Posted 1 year ago #

    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:
    http://codex.wordpress.org/Plugin_API and http://ottopress.com/2011/actions-and-filters-are-not-the-same-thing/

  5. rbergeron81
    Member
    Posted 1 year ago #

    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.

  6. rbergeron81
    Member
    Posted 1 year ago #

    This is now resolved.

  7. jrf
    Member
    Plugin Contributor

    Posted 1 year ago #

    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

  8. rbergeron81
    Member
    Posted 1 year ago #

    Yup, that works.

    Thanks again.

  9. jrf
    Member
    Plugin Contributor

    Posted 1 year ago #

    @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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.