When I hit activate on my custom code that I was helped with it gives me an error and makes my site go critical error.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jason,
Thank you for getting in touch.
What we recommend doing here is to enable the wordpress debugging functions to understand the error being thrown.
To enable the wordpress debugging you will either need to log into your website using FTP or using your Host's CPanel's file manager.
From there you will need to edit the wp-config file by adding the following.
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
If the define( 'WP_DEBUG', true ); function already exists you will need to change 'false' to 'true'
Once you've done this please revisit the page with the issue and let me know what the issue is.
Thanks,
Shane
I did what you said but I did not see any error log pop up, it still just says error updating code snippets
this pops up Deprecated: Non-static method OWA_Block::register_widget_sidebar() should not be called statically in /var/web/site/public_html/wp-includes/class-wp-hook.php on line 307
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jason,
What is the code snippet that you're using ?
There seems to be an error in the actual code itself.
Thanks,
Shane
<?php
/**
*Get file name instead of url.
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Add Shortcode
function trim_urlbasename( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'url' => '',
),
$atts
);
return basename($atts['url']).PHP_EOL;
}
?>
add_shortcode( 'trim_urlbasename', 'trim_urlbasename' );
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jason,
Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this one for you?
I've enabled the private fields for your next response.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jason,
The issue was with the function name.
I had to change the function name to get_filefromurl and change the shortcode name itself to [get_filefromurl] so you should be ok now.
Using the new shortcode should work as well your function is now saving correctly.
Thanks,
Shane
Okay now that I have the code right how would I use it to trim the urls of my custom field call upload-file
here is the custom function you made
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment
// Add Shortcode
function get_filefromurl( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'url' => '',
),
$atts
);
return basename($atts['url']).PHP_EOL;
}
add_shortcode( 'get_filefromurl', 'get_filefromurl' );
I want to trim the url of upload-file in a repeating field
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jason,
As described in one of our previous tickets. To do this you will need to format the shortcode like below.
<ol>[wpv-for-each field="wpcf-upload-file"]
<li><a href="[types field='upload-file' output='raw']> [get_filefromurl url="[types field='upload-file' output='raw']"]</a></li>
[/wpv-for-each]</ol>
Please let me know if this helps.
Thanks,
Shane
After I insert that code I just get the number but nothing shows up like the files name as it should
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jason,
Could you send me a link to the page where you're displaying the fields with the code?
Thanks,
Shane
I can’t send a link because when I try and it doesn’t work I have to revert back to what I need to be showing because it’s on an active template on the site. So any property page with file uploads would have it for example and if it’s broke I can’t publish that on the page
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Jason,
The issue should now be resolved. The problem was that anytime you copy and paste the code from our forums it will break the formatting when you paste it onto your site.
I had to manually type the shortcode and html structure on your site for it to work correctly.
hidden link
If you check the very bottom of this page you will see the file name being displayed.
Thanks,
Shane
I see that the file is being displayed but when I try to put it in the repeating field nothing works it shows "] or ir shows types but not the actual url