• Resolved marcoatmac

    (@marcoatmac)


    Hi everybody,
    I’m trying to add a shortcode (gtranslate flag) into a div in top left header.

    I tried some function but anyone work, can you help me please?
    MY DIV IS :

    
    div class="header__info__items-left"
    

    MY SHORTCODE IS: do_shortcode(‘[gtranslate]’)

    
    
    /*FUNCTION 1
    add_action( 'woo_post_inside_before',     'woo_add_custom' ); 
    
    function woo_add_custom() { 
    
    if (is_single()) {
        echo '<div class="header__info__items-left">'.echo do_shortcode('[gtranslate]').'</div>';
    }
    
    /*FUNCTION 2
    
    add_action( 'woo_post_inside_before',     'woo_add_custom' ); 
    
    function woo_add_custom() { 
    
    if (is_single()) {
        ?>
    <div class="header__info__items-left"><?php echo do_shortcode('[gtranslate]'); ?></div>
        <?php
    }
    
    /*FUNCTION 3
    function addflags_div() {
        if ( is_page() ) {
            ?>
            <div class="header__info__items-left"><?php echo do_shortcode('[gtranslate]'); ?></div>
            <?php
        }
    }
    add_action( 'addflags_top', 'addflags_div' );
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m assuming you tried both 1 & 2, but not both at the same time, since in PHP you cannot redeclare a function with the same name. Both appear to be independently valid (but not together). You do need to remove the second echo in #1. Define WP_DEBUG as true to catch blunders like this.

    I question if ‘woo_post_inside_before’ is a valid action. Do you actually see a do_action() call somewhere using that name? Or is it well documented somewhere?

    It could be is_single() is inapplicable. As a test, add || true to the conditional so there’s always output if the action is valid.

    Thread Starter marcoatmac

    (@marcoatmac)

    Hi @bcworkz thank you.
    Yes, I tried them one at a time

    #function 1
    – I deleted 2° echo
    – I added define( ‘WP_DEBUG’, true );
    – <?php echo do_shortcode(‘[gtranslate]’); ?> is the code from gtranslate plugin official
    to use the shortode by php
    – I tried to change is_single with is_page

    But I can’t see debugging, I don’t understand why
    So, now is this one but doesn’t work yet

    add_action( 'woo_post_inside_before', 'woo_add_custom' ); 
    
    function woo_add_custom() { 
    
    if (is_page()) {
        echo '<div class="header__info__items-left">'.do_shortcode('[gtranslate]').'</div>';
    }}
    define( 'WP_DEBUG', true );
    Moderator bcworkz

    (@bcworkz)

    There’s already a WP_DEBUG definition in wp-config.php as false. You need to change it there. We’re not allowed to re-define constants like this one.

    Thread Starter marcoatmac

    (@marcoatmac)

    done it
    thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘shotcode in a div’ is closed to new replies.