• JMunce

    (@jmunce)


    Some of my plugins come with shortcode that can be inserted into the text side of the editor. I can use this no problem, but I would like to be able to insert this into a custom single so that I don’t have to enter it each time.

    I’m using this in my single.php

    <?php the_content(); ?>
                    <?php endwhile;
                        else :
                        echo '<p>No content found</p>';
                        endif;
                ?>

    Can I put <!– whatever shortcode –> into the loop somehow on my php file?

    Thanks

Viewing 10 replies - 1 through 10 (of 10 total)
  • Michael

    (@alchymyth)

    Thread Starter JMunce

    (@jmunce)

    I did, but it doesn’t provide examples of use or a description of how to implement the code.

    Michael

    (@alchymyth)

    there are some examples at the bottom of the linked source, under ‘User Contributed Notes’

    i.e.
    <?php echo do_shortcode( '[contact-form-7 id="91" title="quote"]' ); ?>

    details might depend on theexact shortcodes you are intending to use.

    Thread Starter JMunce

    (@jmunce)

    Yes, isn’t that just to insert shortcodes onto a page –like if you want to insert a plugin by shortcode? I have done that before.

    What I’m trying to do is insert what I would otherwise paste into the text side of the editor (so it’s actually in the content) so that all the custom pages will be just as though I had done that.

    My shortcode is <!–OffDef–><!–Ads1–>

    Michael

    (@alchymyth)

    My shortcode is <!–OffDef–><!–Ads1–>

    that is unfortunately no shortcode in the sense as WordPress uses it.

    for your kind of code, you might need to ask in the forum of your plugin, or contact the developer of the plugin for help.

    Thread Starter JMunce

    (@jmunce)

    Yes, the plugin author is no longer tending his support, which is why I tried here. There are several plugins that seem to use this kind of procedure though, to alter how their elements display within the text of an article.

    Hopefully someone on here will have experience with it.

    Thanks anyways

    Michael

    (@alchymyth)

    it will be really useful if you could name those plugins your are using.

    some of those plugins are using preg-replace coding via a filter, in which case it might work if you try this code:

    <?php echo apply_filters( 'the_content', '<!--OffDef--><!--Ads1-->' ); ?>

    Thread Starter JMunce

    (@jmunce)

    The one in question at the moment is Quick Adsense.

    I tried a few things with that line of code. I might be using it wrong, but I could only make it display the ads only (no content) if I use

    <?php echo apply_filters( 'the_content', '<!--OffDef--><!--Ads1-->' ); ?>

    in place of

    <?php the_content(); ?>

    And if I try to combine the two (various ways) it displays double the ads with the same amount of content.

    yomisimie

    (@yomisimie)

    You should create a new function in functions.php and add your code to that function, then in single just call that new function.

    Michael

    (@alchymyth)

    I could only make it display the ads only (no content) if I use … in place of …

    correct.

    if you want the ads after the content, try:

    <?php echo apply_filters( 'the_content', get_the_content() . '<!--OffDef--><!--Ads1-->' ); ?>
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to add (text editor) shortcode into php’ is closed to new replies.