function flx_social_sharing_buttons($content) {
// Show this on post and page only. Add filter is_home() for home page
if(is_singular()){
// Get current page URL
$shortURL = get_permalink();
// Get current page title
$shortTitle = get_the_title();`enter code here`
// Construct sharing URL without using any script
$twitterURL = 'https://twitter.com/intent/tweet?text='.$shortTitle.'&url='.$shortURL.'&via=flx';
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$shortURL;
$googleURL = 'https://plus.google.com/share?url='.$shortURL;
$tumblrURL = 'http://www.tumblr.com/share/link?url='.$shortURL;
// Add sharing button at the end of page/page content
$content .= '<div class="flx-social">';
$content .= '<a class="flx-link flx-facebook" href="'.$facebookURL.'" target="_blank"><i class="fa fa-facebook"></i></a>';
$content .= '<a class="flx-link flx-twitter" href="'. $twitterURL .'" target="_blank"><i class="fa fa-twitter"></i></a>';
$content .= '<a class="flx-link flx-googleplus" href="'.$googleURL.'" target="_blank"><i class="fa fa-google-plus"></i></a>';
$content .= '<a class="flx-link flx-tumblr" href="'.$tumblrURL.'" target="_blank"><i class="fa fa-tumblr"></i></a>';
$content .= '</div>';
return $content;
}else{
// if not post/page then don't include sharing button
return $content;
}
};
add_filter( 'the_content', 'flx_social_sharing_buttons');
i use this code to display sociAl sharing buttons below my post ,
i need to add shortcode functionality so that it appears wherever i want
how to do it pls help
You simply can do it with bellow code,
<?php echo do_shortcode('[the_content]'); ?>
just pest this code where you want social icons and u can get it on those place.
I'm not sure that I understand your question correctly, but hopefully you'll be able to use the following to address your challenge.
If I wanted to repurpose the function to render the social sharing buttons, I would start of by changed the first line to
function flx_social_sharing_buttons($content = false) {
The code should at this stage still, as expected, add the social sharing buttons after each post. To add it programmatically or within a post or page you can add the following line, creating a shortcode:
// Add the [my-social-buttons] shortcode
add_shortcode( 'my-social-buttons', 'flx_social_sharing_buttons' );
Documentation available at: https://codex.wordpress.org/Shortcode_API
Great resource for creating shortcodes and other Wordpress features:
http://generatewp.com
You can now use the shortcode in a post or page. To use it inside a php file, do the following
echo do_shortcode('[my-social-buttons]');
If you find that you'd rather now use your function programatically all that's left to do is to remove the original hook, if your social sharing buttons are now duplicated:
// Remove or comment out
// add_filter( 'the_content', 'flx_social_sharing_buttons');
Related
I'm currently using this code with a hook to a specific product but the button seems to be appearing for all other products on my website as well.
add_action('woocommerce_after_add_to_cart_button','additional_single_product_button');
function additional_single_product_button() {
$product_ids = is_single(871);
echo "<br>";
echo "<br>";
echo '<div>';
echo '<a data-type="inline" class="button alt" href="/contact-us/">Pay at Spa # $218 nett</a>';
echo '</div>';}
Here's my website: http://offers.elements.com.sg/
Please advise how I can just add this button for a specific product. Thank you.
I'm trying to insert a button to show at the end of each post on Wordpress in which the link it goes to is defined by a setup using the custom fields plugin. When creating each post, I am able to select the link I wish to display.
Here is the code I have which I know is wrong but I was hoping someone could help here.
function wpb_after_post_content($content){
if (is_single()) {
$content .= 'Contact Franchise →';
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
I assume $franchise_profile_url is a variable and you should concatenate it in the string like this
$content .= 'Contact Franchise →';
function afterContent($content) {
if(!is_feed() && !is_home()) {
$content.= "<div class='footNote'>";
$content.= "<h4>Click the below button if you like it:</h4>";
$content.= "<p><a href='#'>LIKE</a></p>";
$content.= "</div>";
}
return $content;
}
add_filter ('the_content', 'afterContent');
Use the above function. It will help you to achieve what you need.
Thanks for the help here, however, that code simply links back to the post itself and isn't pulling in the URL as set on the post using custom fields. This is the code I had set up before which was working on a default post setup but now I wish to use an alternative method in the functions.php file
<?php if( get_field('franchise_profile_url') ): ?>
Contact Franchise →
<?php endif; ?>
I'm developing a website whereby I would like customers to be able to constantly view the contents of their cart so they can add/remove items on the fly (using WooCommerce).
The theme I'm currently using is Flatsome (with the UXBuilder)
I've noticed there is a template for the WooCommerce mini-cart in woocommerce/templates/mini-cart.php. This looks like what I want to be displayed on my page
I have a plugin called WooCommerce Product Tables that (I believe) displays this mini-cart like this
I was wondering if there is any way for me to display this as a fixed element (within a div perhaps) on my page?
I'm quite inexperienced, so any help is appreciated :)
As Bhoomi suggested, using woocommerce_mini_cart(); works however ajax cart doesn't update the minit cart.
Using this method I suggest to wrap mini_cart function with "widget_shopping_cart_content" woocommerce class, for example :
<div class="widget_shopping_cart_content"><?php woocommerce_mini_cart(); ?></div>
So with ajax add to cart, the mini cart is updated also.
First Create the shortcode on function.php
// Add Shortcode
function custom_mini_cart() {
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
echo '<span class="cart-items-count count">';
echo WC()->cart->get_cart_contents_count();
echo '</span>';
echo '</div>';
echo '</a>';
echo '<ul class="dropdown-menu dropdown-menu-mini-cart">';
echo '<li> <div class="widget_shopping_cart_content">';
woocommerce_mini_cart();
echo '</div></li></ul>';
}
add_shortcode( '[custom-techno-mini-cart]', 'custom_mini_cart' );
Then add this [custom-techno-mini-cart] short code anywhere on page.
Now add this inside your template
<?php echo do_shortcode(['custom-techno-mini-cart']); ?>
Hope This will help you.
Make your layout according to your requirement in first point.
ADD Like This ALSo using This
woocommerce_mini_cart()
You can use woocommerce_mini_cart() wherever you want to display your minicart.
This function loads the mini-cart.php template to display the mini cart.
I want to do interlinking within wordpress pages and say my URL is www.test.com for example and i have www.test.com/p1 www.test.com/p2 and www.test.com/p3 pages and I want to add p1 and p2 links in p3 from admin side.. right now, I just insert and same for p2.. but if my permanlink changes than i need to change content again.. Is there any solution to this.. so I can able to insert just ID of page with and it will convert it automatically to link.
You can use the shortcode api to generate links with post-ids.
When you add following code into your function.php
add_shortcode('permalink', 'permlink_replace_func');
function permlink_replace_func($atts){
extract(shortcode_atts(array(
'id' => '',
'lable' => 'link'
), $atts));
$permpost = get_post($id);
$html = '<a href="'.get_permalink($id).'" >';
if ($lable==null) {
$html .= $permpost->post_title;
} else {
$html .= $lable;
}
$html .= '</a>';
return $html;
}
you can enter a string like [permalink id ="8" lable="hallo world"] in the content area of a post to get a link to another post per id.
More information about shortcodes you can find at the WordPress Shortcode API.
I am using this code to have a simple gallery on the page:
<?php echo do_shortcode('[gallery itemtag="ul" icontag="li" size="full" columns="0" link="file" ]'); ?>
The problem now is that the end-user has to upload an image via the Media page before selecting this image as featured image.
I know this could be solved by adding the featured image's ID to the shortcode's exclude list, but how to get this ID automatically?
function exclude_thumbnail_from_gallery($null, $attr)
{
if (!$thumbnail_ID = get_post_thumbnail_id())
return $null; // no point carrying on if no thumbnail ID
// temporarily remove the filter, otherwise endless loop!
remove_filter('post_gallery', 'exclude_thumbnail_from_gallery');
// pop in our excluded thumbnail
if (!isset($attr['exclude']) || empty($attr['exclude']))
$attr['exclude'] = array($thumbnail_ID);
elseif (is_array($attr['exclude']))
$attr['exclude'][] = $thumbnail_ID;
// now manually invoke the shortcode handler
$gallery = gallery_shortcode($attr);
// add the filter back
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
// return output to the calling instance of gallery_shortcode()
return $gallery;
}
add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
<?php $id = get_post_thumbnail_id(get_the_ID()); // gets the post thumbnail ID ?>
<?php echo do_shortcode('[gallery exclude='.$id.' link="file" itemtag="div" icontag="span" captiontag="p" size="thumbnail" columns="4" ]'); ?>
How about?
echo do_shortcode('[gallery exclude="' . get_post_thumbnail_id( $post->ID ) . '"]');