• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WordPress Tips, Code Snippets, and How To Tutorials

  • Home
  • Blog
  • Tips
  • Snippets
  • Tutorials
  • Contact

Shortcodes

How to allow shortcodes in product excerpts on WooCommerce on WordPress

November 9, 2019 by admin Leave a Comment

On your WordPress website that uses WooCommerce for ecommerce you may want to allow shortcodes in the product excerpts on there. To do that without a plugin you can then add this code to your functions.php file. You may want to backup your WordPress website before you make updates the file on there.

Update to allow shortcodes in product excerpts on WooCommerce

/**
 * Update to allow shortcodes in product excerpts
 *
 * @author WPSnacks.com
 * @link https://www.wpsnacks.com
 */
if (!function_exists('woocommerce_template_single_excerpt')) {
   function woocommerce_template_single_excerpt( $post ) {
   	   global $post;
       if ($post->post_excerpt) echo '<div itemprop="description">' . do_shortcode(wpautop(wptexturize($post->post_excerpt))) . '</div>';
   }
}

Now if that works for you it would allow shortcodes in WooCommerce product excerpts on your WordPress website on there.

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Functions.php, Shortcodes, WooCommerce

How to add a shortcode to easily display the year in WordPress

October 31, 2019 by admin Leave a Comment

On your WordPress website you may want to make a shortcode that displays the year. You can then add this code to your functions.php file. You may want to backup your WordPress website before you make updates to that on there.

/**
 * Add year shortcode
 *
 * @author WPSnacks.com
 * @link https://www.wpsnacks.com
 */
function the_year() {
  $year = date('Y');
  return $year;
}
add_shortcode('year', 'the_year');

Then if that works for you when you want to use the shortcode you type in [year] and it would display it.

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Functions.php, Shortcodes

How to make a shortcode to display an Adsense Ad

October 11, 2015 by admin 4 Comments

Google Adsense Ads are a great way to earn money from your blog or site. Shortcodes are very useful to bloggers too and can be used to easily display an Adsense Ad that you created and setup in your Google Adsense Account. Just add this WordPress Code Snippet to the functions.php file in your current WordPress theme in order to make a custom Shortcode to display an Adsense Ad in WordPress.
[Read more…] about How to make a shortcode to display an Adsense Ad

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Ads, Functions.php, Shortcodes

How to add a Paypal Donate button link to your site using a shortcode

October 10, 2015 by admin Leave a Comment

Just add this WordPress Code Snippet to the functions.php file in your current WordPress theme in order to create a shortcode that allows you to add a Paypal Donate button link on your site.
[Read more…] about How to add a Paypal Donate button link to your site using a shortcode

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Functions.php, Paypal, Shortcodes

How to show the comment count for a certain WordPress post using a shortcode

October 5, 2015 by admin Leave a Comment

Just add this WordPress Code Snippet to the functions.php file in your current WordPress theme in order to show the comment count for a certain WordPress post using a shortcode.
[Read more…] about How to show the comment count for a certain WordPress post using a shortcode

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Comments, Functions.php, Shortcodes

How to allow shortcodes to work in WordPress text widgets

October 1, 2015 by admin Leave a Comment

If you are using shortcodes in your WordPress site, you may want to make it so they will work in text widgets. This can be especially useful if you are using a plugin that produces a shortcode to call the plugin and want to display it in a sidebar or other widget area. Just add this WordPress Code Snippet to the functions.php file in your current WordPress theme in order to make it so your shortcodes will work when placed in a text widget.
[Read more…] about How to allow shortcodes to work in WordPress text widgets

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Functions.php, Shortcodes, Widgets

How to make custom Shortcodes in WordPress

September 21, 2015 by admin Leave a Comment

Shortcodes are very useful to bloggers. You can use them to easily execute functions you have already created, which especially helpful for functions that are repeated often. Just add this WordPress Code Snippet to the functions.php file in your current WordPress theme in order to make custom Shortcodes in WordPress.
[Read more…] about How to make custom Shortcodes in WordPress

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Functions.php, Shortcodes

How to create a shortcode to display the WordPress site url

September 1, 2015 by admin 6 Comments

Shortcodes are a very useful tool when using WordPress. There are often things you may do a lot and using a shortcode helps make it so you can use one instead of retyping a lot of content. Also, if you are a web developer, you may be creating WordPress themes/sites on a development server that will later be transferred to a client’s server. When doing this, the url during development may not be the same as will be after it is transferred over to the client’s live site and server. This can cause extra work after making the transfer editing links and other text that may have displayed the url. You can use a shortcode to find the current site url and display it based on the url the WordPress theme is currently installed on, so no matter where the theme is used, it will display the correct url, which means you won’t have to change it if you move the theme to a new url. Just add this WordPress Code Snippet to the functions.php file in your current WordPress theme in order to create a shortcode to display the WordPress site’s current url.
[Read more…] about How to create a shortcode to display the WordPress site url

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Functions.php, Links, Shortcodes

How to get custom field value using a shortcode

August 1, 2015 by admin Leave a Comment

Just add this WordPress Code Snippet below to the functions.php file in your current WordPress theme to allow you to get custom field values by simply using a shortcode.
[Read more…] about How to get custom field value using a shortcode

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Custom Fields, Functions.php, Shortcodes

How to allow shortcodes to work in Contact Form 7 in WordPress

July 19, 2015 by admin Leave a Comment

Contact Form 7 is a great plugin to make custom contact forms on your WordPress site. If you are using shortcodes in your WordPress site, you may want to make it so they will work in the Contact Form 7 plugin’s contact forms. Just add this WordPress Code Snippet to the functions.php file in your current WordPress theme in order to make it so your shortcodes will work when placed in Contact Form 7 plugin’s contact form.
[Read more…] about How to allow shortcodes to work in Contact Form 7 in WordPress

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Functions.php, Plugins, Shortcodes

  • Go to page 1
  • Go to page 2
  • Go to Next Page »

Primary Sidebar

Hey, We Deliver... Anywhere!

Enter Email Address below to receive our snacks via email:

Join Over 1200 Readers!

Jump To A Random WordPress Tip

Copyright © 2019 • wpsnacks.com