• Resolved fabiano1987

    (@fabiano1987)


    Hi i have a problem with shortcodes inside the adverts single post

    i’ve enabled the shortcodes by adding in the functions.php this code

    add_filter( "adverts_the_content", "do_shortcode" );

    Then i’ve to display the shortcode so i do this:

    <?php echo do_shortcode('[pms-restrict subscription_plans="1830483,1830470"]'); ?>

    This works, but this shortcode needs a “start” (the code above) and an end , which is [/pms-restrict]

    I’ve to close my premium contents between these 2 shortcodes, like this:

    [pms-restrict subscription_plans=”1830483,1830470″]
    content
    [/pms-restrict]

    Now, for the first shortcode, it works fine.. but looks like it doesn’t accept the “closing” shortcode

    Because if i write:
    <?php echo do_shortcode('[/pms-restrict]'); ?>

    on the singlepage i will see the text [/pms-restrict]

    if i write:
    <?php do_shortcode('[/pms-restrict]'); ?>

    i will see no effects, and the content will not be “closed” inside the shortcodes

    That’s what i see on the singlepost advert page

    as you can see, the “start” of the shortcode works.. because it correctly displays a sentence but , since it cannot understand when it finishes, i also see the “Download LIVE Wallpaper” , which i shouldn’t see before to login or register..

    if i do that on a regular single post, i only see “this content is locked please login or register” then, after the login, i will not see this sentence anymore and i see the contents.

    i need a way to make this code to work:
    <?php echo do_shortcode('[/pms-restrict]'); ?>

    • This topic was modified 6 years, 3 months ago by fabiano1987.
    • This topic was modified 6 years, 3 months ago by fabiano1987.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter fabiano1987

    (@fabiano1987)

    After spending some hours on internet i’ve understand why it doesn’t work and what i have to do to have it working .. the problem is that i’m not so good in coding, so i need your help with that (pleaseee)

    The reason

    echo do_shortcode("[/pms-restrict]");

    is not working is because [/pms-restrict] is not a valid shortcode on it’s own. The combination of [pms-restrict] and [/pms-restrict] is valid so

    echo do_shortcode("[pms-restrict] some content [/pms-restrict]");

    it’s the only thing that can work. (in fact it works)

    MY PROBLEM is that between the 2 shortcodes, i need to write php code and i don’t know how to write php inside php

    That’s all the code i need to fix:

    			<?php echo do_shortcode('[pms-restrict subscription_plans="1830483,1830470"] 
    			
    				<p><img src="https://wallpapers.ispazio.net/wp-content/uploads/2018/09/710576-200.png" style="vertical-align: middle; padding-left:15px; height:28px;">&nbsp;&nbsp;<a href="<?php the_field('live_wallpaper'); ?>" class="count" target="_blank">Download the <strong>LIVE Wallpaper</a></strong><?php if( get_field('autore_sfondo') ): ?> - Created by <?php the_field('autore_sfondo'); ?><?php endif; ?></p>
    				<hr style="margin: 10px 0 20px;">
    				<p style="margin:-5px 10px 15px 0;font-size:0.9em;"><ul>
     				<li><i style="color:#e12840;" class="icon-info"></i><b>How to Set the LIVE Wallpaper?</b><a href="#" target="_blank" rel="noopener"> Instructions are here.</a>
    				<b></b></li>
    				<li><b>📢   Broken/Expired Link?</b> <a href="#" target="_blank" rel="noopener">Read This.</a></li>
    				</ul></p>
    				
    			[/pms-restrict]'); ?>

    Everything works, except these 4 parts:

    • <a href="<?php the_field('live_wallpaper'); ?>
    • <?php if( get_field(‘autore_sfondo’) ): ?>
    • <?php the_field( ‘autore_sfondo’ ); ?>
    • <?php endif; ?>

    I tried to add a \ before the ‘
    in this way on the front page i don’t have any errors but the a href link is not working and the fields are not displayed (everything else, works)

    I think the correct approach is by using these '. php .' but i don’t know how to transform the part in which i check <?php IF ( get_field(‘autore_sfondo’) ) exsists and the “endif”

    Please help me to fix the code .. i don’t know how to write this php inside a <?php do_shortcode … […] ;?>

    • This reply was modified 6 years, 3 months ago by fabiano1987.
    • This reply was modified 6 years, 3 months ago by fabiano1987.
    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    this is more of PHP/WordPress question rather than the WPAdverts question, either way, what you would need to do is generate the HTML from PHP first and then parse the whole code with do_shortcode function like this

    
    
    <?php ob_start(); ?>
        <p><img src="https://wallpapers.ispazio.net/wp-content/uploads/2018/09/710576-200.png" style="vertical-align: middle; padding-left:15px; height:28px;">&nbsp;&nbsp;<a href="<?php the_field('live_wallpaper'); ?>" class="count" target="_blank">Download the <strong>LIVE Wallpaper</a></strong><?php if( get_field('autore_sfondo') ): ?> - Created by <?php the_field('autore_sfondo'); ?><?php endif; ?></p>
        <hr style="margin: 10px 0 20px;">
        <p style="margin:-5px 10px 15px 0;font-size:0.9em;">
            <ul>
                <li>
                    <i style="color:#e12840;" class="icon-info"></i>
                    <b>How to Set the LIVE Wallpaper?</b>
                    <a href="#" target="_blank" rel="noopener"> Instructions are here.</a>
                    <b></b>
                </li>
                <li>
                    <b>📢   Broken/Expired Link?</b> 
                    <a href="#" target="_blank" rel="noopener">Read This.</a>
                </li>
            </ul>
        </p>
    <?php $content = ob_get_clean(); ?>		
    <?php echo do_shortcode('[pms-restrict subscription_plans="1830483,1830470"]'.$content.'[/pms-restrict]'); ?>
    
    Thread Starter fabiano1987

    (@fabiano1987)

    thank you very very very much

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Problems using Shortcodes in Adverts SinglePost’ is closed to new replies.