Auto adding shortcode (adrotate) at the end of each event

Hello,
How can I add a shortcode at the end of each event automatically?
I desire to add a shortcode (adrotate) at the end of each event without doing it manually.
Thanks

Lionel

  • Michelle Shull

    Hi there, Lionel!

    The easiest way would be to copy single-incsub-event.php from the plugin folder to the root folder of your theme, and adding the PHP code for the shortcode (not the shortcode itself, it may take a little detective work to find the actual function that's called by the shortcode.) to that single event template you moved to your theme folder.

    If you want to ad to appear at the end of the single event posts, you'll paste the shortcode code before this line:
    <?php get_footer('event'); ?>

    If you can point us toward the plugin that generates this ad rotate shortcode, we may be able to help you track down the code you need. :slight_smile:

    Thanks!

  • Ash

    Hello @Lionel

    I hope you are well today.

    The current single-incsub_event.php has no sidebar integrated. You need to customize the file to match your current theme's page structure.

    Another way could be instead of using single-incsub_event.php file in your theme folder, you can use the following code:

    add_action( 'wp_footer', 'add_shortcode_in_event' );
    function add_shortcode_in_event() {
        ?>
        <script type="text/javascript">
            jQuery(function($) {
    		$('#wpmudevents-single').append('<?php echo do_shortcode( '[ois skin="2"]' ); ?>');
    	});
        </script>
        <?php
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers
    Ash

    • Lionel

      Hi Ashok,

      Thanks for the tip of using Mu-pluginsBut still not working
      I put that code on a new php file named ois.php on mu-plugins folder

      <!doctype html>
      <html>
      <head>
      <meta charset="UTF-8">
      <title>oisskin2</title>
      </head>
      
      add_action( 'wp_footer', 'add_shortcode_in_event' );
      function add_shortcode_in_event() {
          ?>
          <script type="text/javascript">
              jQuery(function($) {
      		$('#wpmudevents-single').append('<?php echo do_shortcode( '[ois skin="2"]' ); ?>');
      	});
          </script>
          <?php
      }
      <body>
      </body>
      </html>

      What can I do to make it work? Thanks a lot.

      Lionel

  • Ash

    Hi @Lionel

    You need to not use html head and other tag, this is php code :slight_smile:

    Please try this:

    <?php
    
    add_action( 'wp_footer', 'add_shortcode_in_event' );
    function add_shortcode_in_event() {
        ?>
        <script type="text/javascript">
            jQuery(function($) {
    		$('#wpmudevents-single').append('<?php echo do_shortcode( '[ois skin="2"]' ); ?>');
    	});
        </script>
        <?php
    }

    Let me know if it works.

    Cheers
    Ash

  • Vinod Dalvi

    Hi @Lionel

    Could you please try using the attached small plugin containing the following code which is working fie for me on my test site?

    add_filter( 'the_content', 'add_shortcode_in_event' );
    function add_shortcode_in_event( $content ) {
    	if( is_singular('incsub_event') ){
    		$content .= do_shortcode( '[ois skin="2"]' );
    	}
    	return $content;
    }

    If for some reason it doesn't work for you on your site then would you mind if I logged in to your site and did some troubleshooting? This might help get to the bottom of this faster. If this is ok, just grant me temporary admin access to your site by clicking "Grant Access" button in the WPMU DEV Dashboard Settings as described on the following page and reply on this thread after granting it?

    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    Best Regards,
    Vinod Dalvi

  • Vinod Dalvi

    Hi Lionel,

    You were getting this "Cannot redeclare add_shortcode_in_event" error message because you had already declared the function add_shortcode_in_event in the functions.php file of your child theme which is also declared in the quick plugin that i have shared.

    To resolve the issue i have commented the existing code and the function add_shortcode_in_event that you had added in the functions.php file of your child theme and now the shortcode is getting appended at the end of the event content as shown in the attached screenshot.

    The code added in the functions.php file of your child theme is not in use now so you can remove it.

    Could you please check the output and let me know whether it's working fine for you or not?

    Regards,
    Vinod Dalvi

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.