WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Passing variables?! Halp! (3 posts)

  1. mhains
    Member
    Posted 4 years ago #

    I've created a function to generate "buttons" on the site, but the following doesn't appear to work:

    <?php $thetitle=the_title(); ?>
    <?php echo button($type,$link,$icon,$thetitle); ?>

    When I do this, the title for the button ends up blank. If I manually insert text, the text appears (so I know the function works)

    How do I pass WP variables like the_title(), the_permalink(), the_date() etcetera?

    Hope you can help!

  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    Nothing posted above is a function, and the_title() is a function call, not a variable..

    For storing values in variables you need a return value from the function call, the_title prints it's result, you can't store the value if it prints, you need a return value.

    Please see.
    http://codex.wordpress.org/Template_Tags/get_the_title

    ..for a return value..

    Other:
    http://codex.wordpress.org/Template_Tags/get_permalink
    http://codex.wordpress.org/Template_Tags/the_date (see echo parameter regarding a return value)

  3. mhains
    Member
    Posted 4 years ago #

    THANKS so much for this!

Topic Closed

This topic has been closed to new replies.

About this Topic