Archived topic
Shortcode in PHP
17 replies · Started by Fulvio on June 6, 2017
i need to insert a short code in the file content-single.php for adding a post rating.
i tried to insert the shortcode in the php file but don't take effect.
is possible to add shortcode in php file? if not, there is another solution?
actually i put the rating using a base html formatting and the php code for call the plugin rating
you can see it below the autorbox.
http://new.sarao.it/fonti-di-traffico-clienti-per-ecommerce/
but i want to make a background color and other formatting
thanks a lot
Fulvio
sorry,
I forgot to add a specific.
I add this but don't take effect too:
<?php if ( is_single() ) { ?>
[elementor-template id="16040"]
<?php } ?>
Hi Fulvio,
try replacing shortcode with:
echo do_shortcode("[elementor-template id='16040']");
David
i tried inserting the code it in the php file but notthing
<?php if ( is_single() ) { ?>
echo do_shortcode("[elementor-template id='16040']");
<?php } ?>
i make a test and i put anly the code you gave me:
echo do_shortcode("[elementor-template id='16040']");
but no way to obtayn something
Hi Fulvio,
i would suggest reading Tom's guide on adding php
Its not recommended to edit php directly.
Also read about using hooks as this might be an easier way to add the content.
Sorry i cant be much more help - Tom and Leo are the experts!
thanks david, i read the 2 article, but seams are very poor of information, i try to study how make this hooks
thanks
Hi Fulvio
try adding YOUR original code to the After Content GP Hook.
The GP Hook's are found under the Appearance menu on your dashboard.
Your code would look like this:
<?php if ( is_single() ) {
echo do_shortcode("[elementor-template id='16040']");
} ?>
Definitely use GP Hooks instead of altering core files.
Hey Tom,
Any way to combine the technique you outline here (https://generatepress.com/forums/topic/adding-a-button-to-menu-workaround/#post-109155) with an Elementor shortcode. So one could design the button (or social icons or whatever) using Elementor, and then insert it in the same way that you showed in that other thread.
This forum truly is awesome. I almost always find what I'm looking for :)
Hmm, I'm not sure that would be possible unless Elementor itself can create the shortcode?
It's a little advanced, but you could design the button in Elementor and then copy the HTML/CSS and use it elsewhere?
<?php if ( is_single() ) {
echo do_shortcode("[elementor-template id='16040']");
} ?>
this solved my request.
Thanks a lot to all
Glad we could help :)
Hey Tom,
So instead of this:
<a class="my-custom-button" href="button URL">Button text</a>
is it not possible to add one of the Elementor shortcodes, somehow:
[elementor-template id='16040']
Wanted to make sure you were clear on what I was referring to :)
It would be amazing to design something in Elementor and be able to add it to the navigation menu using the add_action. I'd considered designing it then using the html/css, but I haven't looked into how easy that would be.
Thanks!
I don't think that would be do-able, unless that elementor template was only a button.. Worth a try though?
Might be overkill just for a simple button.
Yeah, my only thought is that Elementor makes it so easy to design buttons and icons. I can make my way through with CSS but if I can get away without it, I thought I'd try.
Thanks Tom!