Hi,
Is it possible to insert a PHP code into a specific post type build with Toolset?
I have a rating plugin, and I need to display specific data from that plugin using PHP.
Thanks,
Nadav
Hi there,
You need to create a shortcode using WordPress standard methods:
https://developer.wordpress.org/reference/functions/add_shortcode/
You can add the PHP code inside that shortcode, and you can add the whole code to Toolset:
https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#
After that, you need to create a content template and assign it to the post type and use the shortcode there:
https://toolset.com/glossary/template/
Thanks
Thank you for this, but I'm afraid I have an error.
I don't really know PHP but I got this code from the plugin developer:
<?php echo (esc_html(YasrMultiSetData::returnMultiSetAverage)): ?>
Later he wrote: "Typo, is ; at the end of the line"
I tried adding the text to a new customer code and got an error. I tried changing it a bit according to some samples I saw on the links you sent and wrote this:
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
[echo (esc_html(YasrMultiSetData::returnMultiSetAverage))];
?>
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
I still have a warning, and I'm not sure why.
Any chance you can understand what's wrong with the info I provided?
Thanks
Hi there,
This is something that you need to consult with the plugin developer or hire a developer to check. We are unable to check the validity of someone else's PHP code.
Having said that, the correct code should be something like this:
<?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.
echo (esc_html(YasrMultiSetData::returnMultiSetAverage));
Please consider that I do not know what YasrMultiSetData::returnMultiSetAverage section of the code does as it seems to be a custom static class call.
You need to contact the developer who created that code.
Thanks
Thanks,
I've contacted the plugin developer and made the adjustments you and him suggested.
Now the are no errors.
But I still can't figure out to add that 'Custom code snippets' to the post template. I've tried adding ShortCode block and write the snippet name, but it didn't work.
Thanks
Hi there,
We mentioned the documentation on how to add a shortcode. If the documentation is not what you can implement please consider getting help from a developer.
You can find a list here:
https://toolset.com/contractors/
The only thing that I can suggest is to wrap the code that you have inside a shortcode such as:
<?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( 'chrcustomcode', 'chr_custom_code_func' );
function chr_custom_code_func() {
echo (esc_html(YasrMultiSetData::returnMultiSetAverage));
}
Then you will be able to use the Shortcode block in the content template and add [chrcustomcode] there as the shortcode value.
If it does not work for you you need to get help from a developer.
Thanks.
My issue is resolved now. Thank you!