Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Ian Dunn

    (@iandunn)

    The following works for me:
    <?php echo do_shortcode( '[tagregator hashtag="wordpress"]' ); ?>

    Did you remember to echo the string that do_shortcode() returns?

    Thread Starter mobetman2

    (@mobetman2)

    Ian,

    Thanks for getting back so quickly. I figured out the issue with the shortcode but now I’m having another related challenge I’m hoping you can offer advice on.

    I’m setting up an event website and want to use your plugin to track social buzz around each event hashtag. I’m using your shortcode in a sidebar widget which works great.

    Here’s the challenge. Each event will have a different hashtag so I can’t use a static string. My solution was to setup a custom field and use PHP to grab the hashtag per event post using the following code:

    <?php
           $postid = get_the_ID();
           $posthashtag = get_post_field( 'hashtag', $postid );
      ?>

    The code works and it retrieves the hashtag perfectly. I have it output to show a page visitor what hashtag is being searched.

    However, when I use the code inside of your plugin shortcode it doesn’t work.

    [tagregator hashtag= “<?php echo get_post_field( ‘hashtag’, $postid ) ?>”]

    The code is actually working but the plugin seems to executing before the retrieving the hashtag. I think this is happening because when I tried the following code:

    [tagregator hashtag= "#wordcamp, <?php echo get_post_field( 'hashtag', $postid ) ?>"]   or 
    
    [tagregator hashtag= "#wordcamp, <?php echo $posthashtag ?>"]

    Only the wordcamp hashtag displays but if instead of using the code and I use two strings like #wordcamp, #nba they both work.

    I tried executing the code in the child theme functions.php file, page template (which is how I started this thread) but nothing seems to be working.

    I then tried to use the above code and store the entire shortcode into a variable ($posthash) and then echo that variable thinking it might return the shortcode without the embedded code.

    It didn’t work because it somehow conflicted with the plugin. However, if I changed the word “tagregator” to anything else like “regator” the code worked and display the entire shortcode in the sidebar as text. But if the correct shortcode was used, it returned blank.

    It’s been frustrating for me to try and devise a fix for this. Any advice on how to insert a dynamic variable into the shortcode?

    Thread Starter mobetman2

    (@mobetman2)

    Any suggestions on how to fix the issue I mentioned in my earlier post? Would like to get this working if possible.

    Thread Starter mobetman2

    (@mobetman2)

    Anyone have a suggestion on how to get the dynamic variable to execute BEFORE the tagregator shortcode? I’ve researched and tried everything I know but no success.

    Did you get this to work? I wanted to do something similar so wrote this code (I am new to php so if anyone wants to clean it up feel free):

    <?php
    $posttags = get_the_tags();
    $phtag = '';
    $count=0;
    if ($posttags) {
      foreach($posttags as $tag) {
        $count++;
        if (1 == $count) {
    	  $phtag = $tag->name ;
    	  trim($phtag, " ");
        }
      }
    }
    $t='';
    $t .= '[tagregator hashtag="#'.$phtag.'" layout="one-column"]';
    
    if ($t ==='[tagregator hashtag="#" layout="one-column"]') {
    	echo "";
    	} else {
    	echo do_shortcode( $t );
    	}
    
    ?>

    Thread Starter mobetman2

    (@mobetman2)

    @dadragon, no I never got it to work properly. Is the code you wrote working for you?

    yes it works fine, the first part checks if there are multiple tags and then pulls the first tag into $phtag

    You might want to edit the layout= bit as per the FAQ

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

The topic ‘Insert Shortcode Into Theme Template’ is closed to new replies.