• Resolved Wolfram Kl?ger

    (@wolframhk)


    Your plugin works like a charm. Except for featured images. To me, there is no reason to exclude featured images from being “lightboxed”, as well.

    How can I include featured images like standard image and gallery blocks?

    Now and then, I forget to set this damned link to media file ??

    How can I link all images by default to their media files?

    Thanks in advance
    Wolfram

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Johannes Kinast

    (@goaroundagain)

    Hi @wolframhk,

    The Featured Image is not a block at the moment, and there is no option to set a link to the media file. Thus, it is not possible to use baguetteBox.js here. From a UI perspective, I think it is also not a good option because on the front page/feed, the featured image is typically linked to the post. I would find it confusing to click on a featured image, and it does not open the article but a lightbox instead.

    You can set the link target to media file for new images/galleries: From WordPress 5.6 on, you can set the default behavior for Link to. Go to yourblog.com/wp-admin/options.php and search for image_default_link_type. Set the value to file and hit save. This will apply to all new Image & Gallery Blocks.

    Thread Starter Wolfram Kl?ger

    (@wolframhk)

    Hi Johannes,

    thanks a lot. That’s a cute trick, setting the image_default_link_type to ‘file’.

    Though, instead of editing wp-admin/options.php, I’d prefer adding a little snippet to my functions.php, via the brave plugin

    Code Snippets

    The idea is “stolen” from writenowdesign.com

    This is my version:

    add_action( 'after_setup_theme', 'whk_image_defaults' );
    
    function whk_image_defaults() {
    	update_option( 'image_default_link_type', 'file' );
    	update_option( 'image_default_size', 'large' );
    	update_option( 'image_default_align', 'center' );
    }

    In addition to link_type, this snippet also defines default_size and default_align to my preferences.

    Works like a charm.

    BUT: featured images, yes, on archives, they are usually linked to full posts, but on single post, they act as the first image below the title. Then, there is no link, and unfortunately no lightbox, as well?!

    Thread Starter Wolfram Kl?ger

    (@wolframhk)

    Meanwhile, I discovered the Gutenberg block “Featured Image” (Beitragsbild).

    Its settings on the right are:

    – Link to post: yes or no (default)
    – Additional CSS classes

    How could I apply your plugin to this block type, the same as to standard image and gallery blocks?

    Of course, I see, I have to promise, I will _never_ activate the link to post switch ??

    Plugin Author Johannes Kinast

    (@goaroundagain)

    Are you using the Gutenberg Plugin? I thought it’s not in the core yet.

    The problem is, baguetteBox.js needs an <a> tag around an image. I think there is no option to link the featured image to the media file. Thus, no option to use baguetteBox.js.

    If you get the media file in an <a> tag around the image (e.g. via your theme), add a CSS class e.g. .featuredimage and add the selector via the baguettebox_selector (since 1.10.0, just released).

    
    apply_filter( 'baguettebox_selector', function($selector) { return $selector . ',.featuredimage'; } )
    

    Regarding your snipped for the functions.php: I think it will update the value on every request in the database: https://developer.www.ads-software.com/reference/functions/update_option/ This could lead to performance issue because there are at least three UPDATE queries on every request.
    I would suggest using the option_{$option} filter: https://developer.www.ads-software.com/reference/hooks/option_option/

    Thread Starter Wolfram Kl?ger

    (@wolframhk)

    Thanks.

    Yes. “Beitragsbild”, english probably “Featured Image”, appears in my standard Gutenberg block selection. No extra extension or something.

    Funny enough. As mentioned, it *has* a link, if the setting is on. If so, of course, it’s linking to itself. I’m too dumb to imagine a useful application but …

    For now, I have to add the featured image twice. One for the featured image setting, one in the content, as standard image block. Then, your plugin does its thing. Kind of weird, but not really a problem.

    Maybe one day I find a better solution, using GeneratePress and GenerateBlocks.

    Regarding the snippet: Probably you’re entirely right. But how would you compose the snippet? I couldn’t find an example for

    apply_filters( “option_{$option}”, mixed $value, string $option )

    applied to

    ‘image_default_link_type’, ‘file’

    That’s above my head ??

    Plugin Author Johannes Kinast

    (@goaroundagain)

    It works this way (PHP 7.4+):

    add_filter('option_image_default_link_type', fn () => 'file');

    Just added this option to my theme.

    Thread Starter Wolfram Kl?ger

    (@wolframhk)

    Thanks again.

    Where / how would I add this option to my theme?

    The snippet from above can be disabled, after running once. It’s the same as if I had modified options.php.

    Plugin Author Johannes Kinast

    (@goaroundagain)

    @wolframhk Just add it to your functions.php. It overrides the image_default_link_type if the option is called.

    Thread Starter Wolfram Kl?ger

    (@wolframhk)

    Johannes, you’re a wizard ??

    Thank you so much. Added. Tested. Works.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Featured Image’ is closed to new replies.