• Resolved Bodhipaksa

    (@haecceity)


    If I have a certain string of text that’s in several places in my website (such as a date or price) is there a way that I could have a piece of code in place of that text in all the various instances it appears, and then update it centrally? And more importantly, how would I do that?

    This would save a lot of work, and prevent me from overlooking some instances of the text. (Let’s assume a search-and-replace wouldn’t work because it would change the text in places where it needed to stay the same.)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Sounds like you want to use a shortcode. It’ll insert into post or page content pretty much anything that PHP is capable of. For example, adding [lorem] into post content could end up being replaced by several paragraphs of Latin-like gibberish. There’s presently no such shortcode, but hopefully it illustrates the concept.

    Another example that does not currently exist but could: [copy] could be replaced by a full copyright declaration using the current year regardless of how old the post is. Or the shortcode handler function could find the publish date of the current post and use that year instead.

    There are endless possibilities on how you could update such a shortcode. There could be a settings page where you input the desired content for any of the shortcodes you create. The simplest way to update would be to simply alter the PHP source code, but it’s not a very user friendly way to do things.

    Shortcodes normally only work within post or page content, but any PHP that generates output can in theory utilize shortcodes by calling do_shortcode().

    Thread Starter Bodhipaksa

    (@haecceity)

    Thank you. That’s exactly what I need to know. I installed the Shortcoder plugin and have now been able to do what I wanted to achieve.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.