PHP/SQL noob here. Based on this question I attempted to change some entries in phpmyadmin for my wordpress blog: I want to all galleries to link to file instead to file attachment (add link="file"
to [gallery]
shortcode). For that I used 'gallery type="rectangular"'
as a search pattern.
However, my attempt (below) is not working. For some posts, I also tried to manually edit the table entries in the database, with no effect either. Yet, when I change something in my wordpress interface, the effect becomes visible immediately both on my homepage and in the database. What I am missing here? Is this even a good idea, and if not, are there alternatives?
UPDATE
mydb.wor9400_posts
SET
post_content =
REPLACE
(
post_content,
'gallery type="rectangular"',
'gallery type="rectangular" link="file"'
)
WHERE
post_content LIKE '%gallery type="rectangular"%'
PHP/SQL noob here. Based on this question I attempted to change some entries in phpmyadmin for my wordpress blog: I want to all galleries to link to file instead to file attachment (add link="file"
to [gallery]
shortcode). For that I used 'gallery type="rectangular"'
as a search pattern.
However, my attempt (below) is not working. For some posts, I also tried to manually edit the table entries in the database, with no effect either. Yet, when I change something in my wordpress interface, the effect becomes visible immediately both on my homepage and in the database. What I am missing here? Is this even a good idea, and if not, are there alternatives?
UPDATE
mydb.wor9400_posts
SET
post_content =
REPLACE
(
post_content,
'gallery type="rectangular"',
'gallery type="rectangular" link="file"'
)
WHERE
post_content LIKE '%gallery type="rectangular"%'
Share
Improve this question
asked Mar 3, 2019 at 11:45
user161982user161982
3
|
1 Answer
Reset to default 0As Birgire mentioned in the comments, you can hook into the gallery output rather than performing a search/replace on the database.
From the WordPress Codex: Function Reference/shortcode atts gallery
Provides the ability to filter the array returned from shortcode_atts().
You want something like this:
add_filter( 'shortcode_atts_gallery', 'gallery_shortcode_exclude_thumbnail', 10, 3 );
function gallery_shortcode_exclude_thumbnail( $result, $defaults, $atts ) {
if ( empty( $atts['link'] ) ) {
$result['link'] = 'file';
}
return $result;
}
Note: you may want to remove or change the condition empty check, depending on your needs.
shortcode_atts_gallery
filter? – birgire Commented Apr 15, 2019 at 16:56