0

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"%'
  • Are you using the correct table? Note you can also add a shortcode filter. – birgire Mar 4 at 8:05
  • it is the correct table. how would I set a filter – mluerig Mar 4 at 20:33
  • Have you looked into the shortcode_atts_gallery filter? – birgire Apr 15 at 16:56
0

As 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.