• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Any Way To Clean This Up?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Any Way To Clean This Up?

This topic is: not resolved

Tagged: clean, dirty, shortcode, string

  • This topic has 2 replies, 2 voices, and was last updated 8 years, 5 months ago by Porter.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • January 15, 2017 at 1:14 pm #199424
    Porter
    Participant

    I'm trying to use a shortcode I wrote, while passing in an attribute with the value returned from get_the_title. The issue is, without wrapping the returned string in quotes, I only get the first word of the title, as the blank space breaks things in the later code with the do_shortcode. To make it work, I did this:

    $shortcode = '[beverage_title title='."'".get_the_title()."'".']'; //This is so drunk!
    echo do_shortcode($shortcode);

    As you can see, the concatenated quotes around get_the_title are borderline ridiculous. The returned value is a string, but it isn't a string wrapped in quotes, which is apparently needed. This works as is, but Is there any cleaner way to write the above code? It's driving me crazy haha.


    Buy me a beer? | Try DigitalOcean VPS Hosting

    January 15, 2017 at 2:21 pm #199426
    Victor Font
    Moderator

    What exactly are your trying to accomplish with the shortcode? You should probably be using the get_the_title() function in the shortcode itself, not passing as a parameter.

    You could assign the output from get_the_title() to a variable and pass the variable. No quotes should be necessary.

    $title = get_the_title();
    $shortcode = '[beverage_title title=$title]'; //This is so drunk!
    echo do_shortcode($shortcode);

    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    January 15, 2017 at 3:14 pm #199432
    Porter
    Participant

    $shortcode = '[beverage_title title=$title]';

    That doesn't work because the variable isn't read, it treats $title as nothing more than a string. Even with the correct code:

    	$title = get_the_title();
    	$shortcode = '[beverage_title title='.$title.']'; //This is so drunk!
    	echo do_shortcode($shortcode);

    I'm only getting the first word of the title. With my original code, I get the entire title, spaces, words following, etc. I Googled this a bit, and for some reason, the value has to be wrapped in quotes, it's odd.


    Buy me a beer? | Try DigitalOcean VPS Hosting

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble