Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$5
Best way to check for [gallery] shortcode in plugin overriding it
// Check for [gallery] shortcode
function have_gallery( $posts ) {
if ( empty( $posts ) || $this->has_gallery )
return $posts;
foreach ( $posts as $post ) {
$pos = strstr( $post->post_content, '[gallery' );
if ( false !== $pos && $pos >= 0 ) {
$this->has_gallery = true;
break;
}
}
if ( $this->has_gallery )
$this->enqueue_assets();
return $posts;
}The plugin/code works fine if the [gallery] shortcode is within the page/post content (WYSIWYG / HTML editor) area, but it doesn't work if do_shortcode('[gallery]'); is used in a page template... AND [gallery] is not in the content area.
Said another way, I have to type [gallery] into the WYSIWYG area in order for do_shortcode('[gallery]'); to work... EVEN THOUGH the content isn't displayed on the page/post/CPT template.
Is there a way to edit/rewrite the code above to be able to play nice with do_shortcode WITHOUT having to do that little trick of entering [gallery] into the WYSIWYG area?
FYI: Related question here: http://wordpress.stackexchange.com/questions/70649/wp-insert-post-data-for-cpt
Thank you.
This question has been answered.
Clifford P | 10/27/12 at 2:55pm
Edit
(1) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
10/27/12
3:03pmArnav Joy says:if you not use [gallery] shortcode in WYSIWYG then how we will know page has a gallery..
- 10/27/12 3:08pm
Clifford P says:I upload images to create the gallery but then want to use it in a page template. Like I said, all works perfectly if I put [gallery] in the content area even though I don't display it at all on the page.
- 10/27/12 3:24pm
Arnav Joy says:try this
<?php
function have_gallery( $posts ) {
if ( empty( $posts ) || $this->has_gallery )
return $posts;
foreach ( $posts as $post ) {
$pos = strstr( $post->post_content, '[gallery' );
$args = array(
'post_type' => 'attachment',
'numberposts' => null,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($args);
if( !empty($attachments )) {
$this->has_gallery = true;
break;
}
}
if ( $this->has_gallery )
$this->enqueue_assets();
return $posts;
}
?> - 10/27/12 5:55pm
Clifford P says:Worked just as desired. Thank you SO much! :-)
- 10/27/12 3:08pm
This question has expired.
Clifford P, Dbranes voted on this question.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
