Adding wordPress shortcode snippet to Frontity

I am trying to use a plugin for language translations in a site. The plugin provides a php shortcode <?php echo do_shortcode('[gtranslate]'); ?> that is supposed to go in the homepage index php file - it creates a dropdown selector, and when you select a language, the site is translated. I am trying to see if this plugin will work on a Frontity site, but am wondering if it’s possible to somehow use the shortcode above? It wouldn’t be able to go in the Frontity side code of course, but I’m not sure if there’s a way of creating a function.php snippet that will allow me to view the dropdown created by the snippet above in the Frontity site?

Hi @maddogdev

If you put the shortcode in the page content then Frontity will display the HTML it generates along with the rest of the content. However, in that case you need to send the value from the dropdown back to WordPress.

Take a look at this repo which shows a way to display shortcode content in Frontity. The repo is the result of this episode of Frontity Talks where we go into more detail.

This may help you with showing the dropdown in the front end of your site, but you still need to get the value of the dropdown back to WordPress. In the example above we use the Contact Form 7 package to send the form data back to WordPress. The code in that package may give you some ideas of how you can do this.

You shouldn’t need to add anything to the functions.php file unless your translation plugin is lacking something, e.g. support for Ajax.

I didn’t quite get it. Are we able to use WordPress shortcodes generated by plugins to display them wherever we want on frontity or we need to use them as part of post / page’s content (which by the way, doesn’t work for me most of the time, the page renders some kind of block but it’s not visible)?

Hi @mh123

Shortcodes won’t work in Frontity. They only work in WordPress as the shortcode triggers some PHP code which generally adds content to the page/post. So the shortcode must be included in the page or post content.

The shortcode-generated content will then be included as part of the content.rendered property in the JSON returned by the REST API.

However, not all shortcodes create content, though I would guess that most do. What isn’t working for you? Can you provide a link to the WordPress site with the shortcodes that are causing problems for you?

I am having same problem on my kitchen reviews website. I am also looking for solution.

Hi @stevendrew39

Welcome to the Frontity community. Can you specify what the problem is that you’re looking for a solution for please.

Shortcodes need to be added to the page/post content in the WordPress admin. The plugin that implements the shortcode will normally add content to the page/post in the place that the shortcode was added, replacing or substituting for the shortcode.

That added content will then be included in the content.rendered property in the JSON returned from the REST API. Once it’s in the JSON Frontity will simply render it along with the rest of the content in the content.rendered property.

If this process is not what you’re experiencing then we’ll need to dig in and figure out what’s going on, so the more information you can provide us with the better. Please see here for the kind of information that will be useful to provide.