• I’m trying to spice up a theme of mine with some shortcode buttons but I’m having quite a bit of trouble when trying to call the author’s name within the button itself. I tried simply including

    <?php echo do_shortcode('[button type="square" color="black" size="small"] Posted by <?php the_author(); ?> [/button]'); ?>

    in the theme where I want the button with the author’s name to appear, but it just gives a button that says ‘Posted by ‘. I’m not the most experienced coder, but I know a little bit of everything from tinkering with various themes over the years. All help is appreciated, thanks in advance! -Matt

Viewing 11 replies - 1 through 11 (of 11 total)
  • Give this a try:

    `<?php echo do_shortcode(‘[button type=”square” color=”black” size=”small”] Posted by ‘ . get_the_author() . ‘ [/button]’); ?>

    Thread Starter techteenager

    (@techteenager)

    vtxzzy, thanks for your response! I actually figured out an easier fix with a CSS workaround, but since you know what you’re doing I want to ask you another question:

    Right now, I’m trying to be able to have a user submit a form with a YouTube URL that makes a draft post w/ the URL entered as a custom field. I can call the custom field in a special part of the theme, but I’m trying to then convert into an autoplaying video with Viper’s Video Quicktags.

    TL;DR: Do you know a way to call a custom field within a shortcode? (This is outside of the loop in a place above the post in the theme)

    -Matt

    Not quite sure what you are asking. If you just want to get the custom fields for a post outside the loop, use get_post_custom with the post ID:

    See the Codex on get_post_custom

    is there only the 1 custom field you need to pull?

    http://codex.wordpress.org/Function_Reference/get_post_custom_values

    might be more appropriate.

    global $post;
    $ytid= get_post_custom_values('youtube_ID', $post->ID);

    where youtube_ID is the name of your custom field. then you should be able to use the $ytid variable in your do_shortcode

    Thread Starter techteenager

    (@techteenager)

    Yeah, I have users fill out a form, where the video URL is entered as the custom field ‘videourl,’ on the article page, the video url is called with the function

    <?php $checkvid = get_post_meta($post->ID, videourl, true); if($checkvid){ ?><?php echo get_post_meta($post->ID, vidauthor, true); ?>
    <?php }else{ ?>
    Hmm, we couldn't find the video.
    <?php } ?>

    This calls the URL out above the post to be displayed. When I first tried this, it worked and everything, but I wanted to get the video to auto-embed & autoplay with Viper’s Video Quicktags. So, around that function to call the URL I wanted to find some way to use [youtube] above function [/youtube] so that it would work.

    So:

    [youtube] <?php $checkvid function.... [/youtube]
    <?php the_content(''); ?> \\ The description of the video would be in the post content, along with a link to the submitter's YouTube channel, etc.

    So I’m now aware that the [youtube] would need a do_shortcode function, but I’m completely clueless as to how I can do this

    Do you guys have any ideas?
    Thank you guys for being so helpful thus far,
    Matt

    yeah if you know you have a youtube url then you can use the shortcode that you’re already looking at.

    i think this ought to work.

    echo do_shortcode('[youtube]'.$checkvid.'[/youtube]');

    Thread Starter techteenager

    (@techteenager)

    Soo close, haha. I tried your code and it calls it and everything, but for some reason it gives me an image. Would it help if I clarify that the $checkvid function is only there to make sure there is a videourl field? (so there isn’t any broken code). What I’m trying to call is the custom field ‘videourl’ inside the shortcode.

    Thanks for your help!! I really appreciate it!
    Matt

    according to the plugin, it will show an image when the URL is busted. try echoing out the checkvid variable to ensure that it has a working URL

    echo $checkvid;
    Thread Starter techteenager

    (@techteenager)

    Sorry, I have no idea where to put that, haha. Here’s what I’ve got in the video container: http://pastebin.com/NgGgdeDa

    Thread Starter techteenager

    (@techteenager)

    If there’s any way I can repay you for helping me so far, just tell me. I don’t have any money (I’m only 17) but if you need a site advertised or you want Twitter followers, just let me know and I can help out.

    you can put it anywhere in your function after you’ve defined it. we’re just trying to see what the value is as hopefully that will tell us why the shortcode isn’t working.

    <div id="video-container">
    	<?php $checkvid = get_post_meta($post->ID, videourl, true); 
    
    echo "what is the video url? " . $checkvid . "<br/>";
    
    if($checkvid){ ?>
    		<?php echo do_shortcode('[youtube]'.$checkvid.'[/youtube]'); ?>
    	<?php }else{ ?>
    		Sorry, we couldn't find the video
    	<?php } ?>
    </div> <!-- video-container -->

    we probably also ought to wrap the shortcode up in a class_exists wrapper to ensure that viper’s plugin is installed

    <?php if(class_exists('VipersVideoQuicktags')):?>
    <div id="video-container">
    	<?php $checkvid = get_post_meta($post->ID, videourl, true); if($checkvid){ ?>
    		<?php echo do_shortcode('[youtube]'.$checkvid.'[/youtube]'); ?>
    	<?php }else{ ?>
    		Sorry, we couldn't find the video
    	<?php } ?>
    </div> <!-- video-container -->
    <?php endif; ?>

    thanks for the offer. one day (cough cough) i will have my portfolio site up, but not yet. but the best thing you can do for me would just be to pay it forward and help someone else down the line. πŸ™‚

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

The topic ‘Help with shortcodes functions’ is closed to new replies.