• I’m new to WordPress but have a lot of experience with creating my own CMSes.

    My question is how can I make a gallery for a post (I’m adding products as posts) without having Editor window. The editor window is not good because the client has to add gallery block himself and then he accidentally can add another one, some texts and etc.

    I need only option to add multiple photos when he is filling in other Custom fields of that product. When he will upload photos he should have a function to change the position of photos and delete some of them. This is the basis of any website which has some products or any kind of other items on it.

    I searched for WP gallery plugins, but all of them designed to create separated galleries and control them on another page. Which doesn’t fit my design…

    Dynamic Featured Photo plugin looks close to this, but it required to upload each photo separately and select each time you want to do this from Media Library or PC… I need a function to select and upload multiple photos at once because sometimes there are 20 of them.

    Which way would be best? This is very basic functionality so I believe someone has already made it… Thank you ??

    • This topic was modified 5 years, 7 months ago by Gediminas.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    It sounds like you like the default gallery block but don’t want to allow the client to add other information into the editor. What if you gave them the editor, but had enforcement code that discards any content outside of a single gallery block?

    You can even define default content for new posts that already has a gallery block. There can even be a warning that any other added content will be discarded, since the warning would also be discarded by such enforcement.

    If other content is required besides the gallery, it could be accomplished through custom fields. The $post->post_content in code would be strictly for gallery content only.

    Thread Starter Gediminas

    (@gediminas10)

    It sounds like you like the default gallery block but don’t want to allow the client to add other information into the editor. What if you gave them the editor, but had enforcement code that discards any content outside of a single gallery block?

    Yes, it would be great! ??

    You can even define default content for new posts that already has a gallery block. There can even be a warning that any other added content will be discarded, since the warning would also be discarded by such enforcement.

    How to do this?

    If other content is required besides the gallery, it could be accomplished through custom fields. The $post->post_content in code would be strictly for gallery content only.

    I made custom fields already. Thank you!!

    • This reply was modified 5 years, 7 months ago by Gediminas.
    Moderator bcworkz

    (@bcworkz)

    I misspoke about inserting a gallery block into all new posts. What I had in mind only works with the classic editor plugin. And then you would only be able to add the classic style [gallery] shortcode. If you want to go that route, this code will do it:

    add_filter( 'the_editor_content', function ( $content ) {
    	if ( $content ) return $content;
    	else return '[gallery]';
    });

    If there is a way to do the same for the block editor in PHP, I’m unaware of what it is. It should at least be possible to insert something via JavaScript/jQuery.

    Which style of editor is used impacts which regexp is used to identify the gallery element within other potential content. Whichever is used, my thought was to preserve the first matching content and discard everything else. This could be a problem should the user enter a second gallery, ignoring the first. There’s no way for code to know the “right” gallery to preserve.

    To do this enforcement, use the “wp_insert_post_data” filter. Your callback is passed most post data, of which code can alter as it sees fit just before WP inserts or updates the post in the DB.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Best way for uploading photos for product’ is closed to new replies.