WordPress.org

Forums

How do I display dynamic text in echoes? (4 posts)

  1. Please Add Screenshots
    Member
    Posted 2 years ago #

    Could anyone help me fix this so that my wp tags work in this piece of code... thanks heaps!

    <?php $typography = of_get_option('example_typography2');
                if ($typography) {
                    echo '<span style="font-family: ' . $typography['face']. '; font-size:'.$typography['size'] . '; font-style: ' . $typography['style'] . '; color:'.$typography['color'].';">
    				<a href="<?php echo get_settings('home'); ?>/"><?php bloginfo('name'); ?></a>
    				</span>';
                } else {
                    echo "no entry";
                } ?>
  2. Marventus
    Member
    Posted 2 years ago #

    Hi!

    Change your 4th line to this:

    <a href="<?php echo home_url(); ?>/"><?php bloginfo('name'); ?></a>

    You could also use get_bloginfo('siteurl'), but it is flagged as deprecated in the correspondingget_bloginfo` Codex article.

    Cheers!

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    you can either switch back and forth from php and echo to html and 'normal' php;
    example:

    <?php $typography = of_get_option('example_typography2');
                if ($typography) {
                    echo '<span style="font-family: ' . $typography['face']. '; font-size:'.$typography['size'] . '; font-style: ' . $typography['style'] . '; color:'.$typography['color'].';">#'; ?>
    				<a href="<?php echo get_settings('home'); ?>/"><?php bloginfo('name'); ?></a>
    				<?php echo '</span>';
                } else {
                    echo "no entry";
                } ?>

    or use proper string concatenation with using those WordPress functions which return the output; such as get_bloginfo() or home_url();
    example:

    <?php $typography = of_get_option('example_typography2');
                if ($typography) {
                    echo '<span style="font-family: ' . $typography['face']. '; font-size:'.$typography['size'] . '; font-style: ' . $typography['style'] . '; color:'.$typography['color'].';">
    				<a href="'. home_url() . '/">'. get_bloginfo('name') .'</a>
    				</span>';
                } else {
                    echo "no entry";
                } ?>

    http://php.net/manual/en/language.operators.string.php

  4. Please Add Screenshots
    Member
    Posted 2 years ago #

    Thanks to both.... I always prefer html/php so thanks so much for that alchymyth!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags