[Resolved] Shortcode in PHP

Home Forums Support Shortcode in PHP

  • This topic has 17 replies, 5 voices, and was last updated 12 months ago by David.
Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #329170
    Fulvio

    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

    GP Premium 1.3
    #329172
    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 } ?>
    #329285
    David
    Staff
    Customer Support

    Hi Fulvio,

    try replacing shortcode with:

    echo do_shortcode("[elementor-template id='16040']");

    David

    #329299
    Fulvio

    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

    #329335
    David
    Staff
    Customer Support

    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!

    #329342
    Fulvio

    thanks david, i read the 2 article, but seams are very poor of information, i try to study how make this hooks
    thanks

    #329368
    David
    Staff
    Customer Support

    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.

    #329379
    Tom
    Lead Developer
    Lead Developer

    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.

    #330227
    Nick

    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 🙂

    #330306
    Tom
    Lead Developer
    Lead Developer

    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?

    #330454
    Fulvio
    <?php if ( is_single() ) { 
        echo do_shortcode("[elementor-template id='16040']");
    } ?>

    this solved my request.
    Thanks a lot to all

    #330690
    Tom
    Lead Developer
    Lead Developer
    #330692
    Nick

    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!

    #330750
    Tom
    Lead Developer
    Lead Developer

    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.

    #330757
    Nick

    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!

Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.