Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #4180
    Lance Elliott
    Participant

    Hello,

    I want to display the attachments at the bottom which I have selected and this works fine.

    On some pages I just want to manually insert the shortcode into a specific location (toggle box) and not have the automatic one appearing at the bottom.

    thoughts?
    Lance

    #4181
    Bartosz
    Keymaster

    Yeah, multiple thoughts :)

    But lets start with this one: there’s a da_display_attachments filter hook that allows you to modify the display of attachments metabox based on any condition. For example:

    function custom_da_display_attachments($html) {
    	if (in_category(1)) { // if current post belongs to category of id 1
    		$html = ''; // do not display the attachments metabox
    	}
    	return $html;
    }
    add_filter('da_display_attachments', 'custom_da_display_attachments');

    But I’m not sure it will work for you.

    So let’s try being a bit more creative. Set your attachments display from before/after the content to manual and let this code handle the display instead:

    function custom_the_content($content) {
    	if(!has_shortcode($content, 'download-attachments')) {
    		// The content doesn't include the [download-attachments] shortcode so display the attachments now
    		$content = $content . do_shortcode('[download-attachments]');
    	}
    	return $content;
    }
    add_filter('the_content', 'custom_the_content');

    It check’s if you used the shotcode it the post content. If you did it does nothing, if you didn’t it will append attachments right after the content.

    #4201
    Lance Elliott
    Participant
    This reply has been marked as private.
    #4634
    Lance Elliott
    Participant

    where do I insert this code? which php file… if I install in in your download-attachments.php surely it will be removed when I update?

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.