Wordpress allows the use of a custom tag called a shortcode. This code allows you to insert code or text by inserting a placeholder tag within the View Mode of Posts or Pages. For example, if you wanted to insert a YouTube video, you would use the shortcode [youtube=http://youtube.com/watch?v=wjhrewkerw] instead of inserting or coding all the code actually needed to embed the video.
Shortcodes can also be used as a shortcut to include longer text that you use repeatedly such as a URL, a signature, or any other type of code. In our example below, we will demonstrate how to create a simple code to display your domain's URL.
Shortcodes are created by modifying the functions.php file for a particular theme. This means if you create a shortcode to use with your current theme and then change themes, you will need to recreate the code in the new theme as well. Shortcodes also consist of two parts. First there is the function, which actually performs any processing, or in our example below, returns the URL you want to display. Second is the hook code. This is the piece of code where you will name the shortcode and connect, or hook, it to the function you create to display your data. Below is a simple set of instructions to help you create your own simple shortcodes.
Editor | Output |
---|---|
n/a Points
|
2016-05-05 3:28 pm
I think there is an error in step 5 when you name your function homeURL. When you call the function, you then use mainDomain. The code in the popup on step 6 is correct. |
Staff 12,339 Points
|
2016-05-06 12:35 am
Hello WebSavvy Studio,
Thank you for contacting us. I tested the article, and you are absolutely correct. I have updated the guide to reflect the correct function name. Let us know if you see any further issues, or have additional article suggestions for us. Thank you, John-Paul |
Email: | support@WebHostingHub.com | Ticket: | Submit a Support Ticket |
---|---|---|---|
Call: |
877-595-4HUB (4482) 757-416-6627 (Intl.) |
Chat: | Click To Chat Now |
We value your feedback!
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
new! - Enter your name and email address above and we will post your feedback in the comments on this page!