Inserting shortcode into woo page with hooks
-
Hi
Thanks for a clever plugin.
I am trying to set up rotating banner ads in Woo on both shop/archive pages and on individual product pages.
I have tried literally dozens of plugin from the WP repository and none of them are any good. Either not enough functions or full of bloat.
I figured I could just use your plugin to create some shortcodes and then insert them into woo using hooks.
And
Step one I created to functions.php snippets to insert the shortcodes into woo pages:
// ADD SHORTCODE TO TOP OF SINGLE PRODUCT add_action( 'woocommerce_before_single_product', 'enfold_customization_extra_product_content', 15 ); function enfold_customization_extra_product_content() { echo do_shortcode("[my-shortcode]"); } // ADD SHORTCODE TO TOP OF SHOP AND ARCHIVE PAGES add_action( 'woocommerce_archive_description', 'woocommerce_archive_description', 15 ); function woocommerce_archive_description() { echo do_shortcode("[my-shortcode]"); }
This works fine and the “dead” shortcodes appear where expected.
I then also added the following php to my functions.php file:
$banner1 = '<a href="https://targetwebsite.com" target="_blank"><img src="https://test.com/wp-content/uploads/2017/11/greenbanner.jpg" alt="BANNER1_ALT" title="BANNER1_TITLE"></a>'; $banner2 = '<a href="https://targetwebsite.com" target="_blank"><img src="https://test.com/wp-content/uploads/2017/11/redbanner.jpg" alt="BANNER2_ALT" title="BANNER2_TITLE"></a>'; $banner3 = '<a href="https://targetwebsite.com" target="_blank"><img src="https://test.com/wp-content/uploads/2017/11/blackbanner.jpg" alt="BANNER3_ALT" title="BANNER3_TITLE"></a>'; $banners = array($banner1, $banner2, $banner3); shuffle($banners);
I then added the following to a shortcoder edit page:
<div> <?php print $banners[0] ?> </div>
And named the resulting shortcode Banners. The result was the following shortcode:
[sc name="Banners"]
But…when I went to replace [my-shortcode] with [sc name=”Banners”] in my functions.php file I get the following error message:
Syntax error, unexpected T_string, expecting ',' or ')'
As a result the addition of your shortcode to my functions.php file breaks my site.
Is there a way to change the name of the shortcode created by your plugin so that it does NOT include “” ?
Or if not do you see any way to make the arrangement I have explained above work?
Thanks in advance for your kind assistance.
Max
- The topic ‘Inserting shortcode into woo page with hooks’ is closed to new replies.