Home›Toolset Professional Support›[Resolved] Size attribute not working in types image shortcode with custom WP directory structure
[Resolved] Size attribute not working in types image shortcode with custom WP directory structure
This thread is resolved. Here is a description of the problem and solution.
Problem:
Size attribute not working in types image shortcode with custom wordpress directory structure
Solution:
The fix is set to be published with Types version 3.1.
Relevant Documentation:
This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Thanks for the screenshots, I can see the image is outputted full-size image even you are using attribute size="thumbnail" in the Types shortcode.
The problem is abnormal, please try this:
1) Dashboard-> Toolset-> Settings-> Custom Content
click "Clear Cached Images" and "Clear Outdated Cached Images", and test again
Also, I've added a custom plugin with just the following shortcode to display the thumbnail. This shortcode does work.
// Render thumbnail image from URL
add_shortcode('image-thumbnail', function () {
// get the image url
$image_url = types_render_field('image', ['output' => 'raw']);
// convert the image url to id
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url));
$image_id = $attachment[0];
// render the thumbnail image
return wp_get_attachment_image($image_id, 'thumbnail');
});
Thanks for the details, it should be a server problem, I have tried these:
1) Export your website setting, and import it into below test site hidden link
user/pass: xgren/111111
2) Create a page, with shortcode:
[types field='image' title='%%TITLE%%' alt='%%ALT%%' size='thumbnail' resize='proportional'][/types]
and upload a new image to test: hidden link
It works fine in front-end: hidden link
There isn't similar problem, it does output the image in thumbnail size: hidden link
You might consider to test it in another web server.
Can you point me to where the code is in the Types plugin that renders the image? The server setup is pretty standard, so perhaps there is an error in Types. I see it works on your test site, but there are other server environments where Types should still work.
Also, using the attribute url='true' does work. The correct thumbnail url is displayed. So it seems more like a problem with how Types is generating the image.
If I set Toolset > Settings > Allow resizing of remote images to true, then a 150x150 image is displayed, but from uploads/1970/, so it is not the actual thumbnail. It has been resized and saved by Types. Why does Types think it is a remote image? I have the following defined in functions.php
Q1) Types can handle such definitions, correct? Also WordPress in a sub directory?
First, those definitions should be put into file wp-config.php,
I suggest you try to remove them, and upload an image and test again.
If it is fixed, then there might some problem with your custom definitions.
Q2) Perhaps an issue with permissions?
Yes, as the error message, there is an issue with file permissions: Destination dir not writable
I suggest you check the Q1 first.
I have tried your definitions settings in my localhost, the wp-content folder does not take effect any more, and I have tried to upload and install Types plugin, but get below error:
The link you followed has expired.
Please try again.
So there should be some wrong in your custom definition .
But I am not sure which definition is wrong, you can debug it like this: remove them one by one, and test again
Did you also modify your directory structure to match the definitions? Of course it will not work if you define content directory as /app, but the directory is still named wp-content. I also have wordpress core files in a subdirectory, so the following definitions are included wp-config.php as well (local dev url shown below, but it's is updated to the correct domain on the live site).
Have you tried it in a fresh wordpress installation? Does it work? Can you confirm it?
I have tried the steps you mentioned above, please correct me if there is anything missing
1) Install a fresh wordpress installation hidden link
2) change the the folder name "wp-content" to "app"
change the the folder name "wp-includes" to "wp"
3) add below codes in wp-config.php:
And test it in front-end, I get this PHP error:
Warning: require(D:\wamp64\www\wordpress/wp-includes/load.php): failed to open stream: No such file or directory in D:\wamp64\www\wordpress\wp-settings.php on line 19
I see that you can generate a custom size, but that is not a solution. That creates a new file and saves it to /uploads/1970/. It does not load the thumbnail size created by WordPress when an image is uploaded. The file I'm trying to load is not an external image, it does not need to be resized by Types. The thumbnail created by WordPress already exists, but the Types shortcode is not able to load it.