Your shares_content
function directly outputs content, which won’t work if you’re trying to assign the results to a variable or use it in a return
statement within another function.
You can change it to return
the string:
function shares_content() {
$content = "<div class="social-shares-container"><a href="https://www.facebook.com/sharer/sharer.php?u=%s">Share on Facebook</a></div>";
return sprintf( $content, get_permalink() );
}
It’s also worth pointing out here the use of get_permalink()
. If you look at the source code, that function also return
s its value. There is another API function, the_permalink()
, which contains an echo
instead of a return
. That would also break your filter output. Most WordPress functions have two versions like this.
Related Posts:
- Remove links from the_content when using filters wp_trim_excerpt
- Changing where my author box is printed
- Insert Content Before div#main from the functions.php File
- Function the_content
- Import WordPress XML File from Within Functions.php
- Does hooking into the same action multiple times drain memory?
- How to influence the information displayed on widget inside wp-admin
- Extract image from content and set it as the featured image
- Is there a hook or function I can use to display all theme files being used on a current page?
- Difference between the_content() and get_post()?
- Show modified time if post is actually modified
- How to create thumbnails for PDF uploads?
- Implementing DNS Prefetching with WordPress
- Help me to understand wp_header() and wp_footer() functions
- How can I add an extra WooCommerce hook
- Remove Page Title from Static Frontpage
- How to override WordPress registration and insert an auto-generated username?
- Set default options for inserting media
- How to hook into the quick edit action?
- Is it possible to be more page/post specific with admin_enqueue_script?
- get_the_excerpt() not returning anything when post has no excerpt
- WooCommerce add_action hook results in 500 error
- Issue adding text after short description on product pages Woocommerce [closed]
- Function to wrap the_content in a div
- Customize “the_posts_pagination” and put list instead div
- Function to show only first instance of shortcode
- Automatically insert php function into post $the_content
- Gravity Forms field entries into wp_query loop [closed]
- Post thumbnail relative link and HTML modify
- Searching for content post
- Accepted arguments value in hook functions
- Get current page_id before loop, in functions.php
- Which action hook to use for function?
- Change size and crop medium_large images
- Gravity Forms – Using a Form to Pre-populate A Gravity Form [closed]
- str_replace function in theme
- Running a script before absolutely everything
- How to display post content instead of excerpt
- Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘greenday_head’ not found or invalid function name
- Modify a function without editing template
- Problem only while using require_once() within functions.php
- Which action does wp_update_user triggers?
- How can I get my Script to work on the Login page?
- Trigger a custom function when option are saved in admin area
- Execute a ultimate member action when user role is updated
- Add other social networks to TwentyNineteen_SVG_Icons class in child theme?
- How to use wp_trash_post (or wp_delete_post) for deleting a (or all) post(s) from custom post type?
- What did I do wrong in my functions code, that will not change the “Get New Password” text to “Send It”?
- Registration Hooks don’t appear to be working
- Pass parameter to hooked function using custom page template
- Add Element as a Filter to the_content
- Hook into a function without a hook?
- Is my code correct to enqueue CSS on a specific page?
- Can’t properly set the_title add_filter to show short_URL
- Insert template-part inside the content
- Filter yoast canonical add_action priority [closed]
- (Woocommerce) Order by price when entering specific category
- How do I hook into the container of wp_nav_menu?
- Is there a way to prevent a function/method from being called outside a specific hook?
- Function not working inside of a function in functions.php
- Adding code before post title with the_title produces weird results
- does wp function the_content(); accept another tag inside
- Add back in child theme what the parent theme removed with remove_action
- Undefined variable error in new function
- Writing a function to detect an event
- This code works, but the way I integrated it is breaking the media uploader. How can I integrate it properly?
- first paragraph of the_content as meta description
- Is it possible to use add_filter in an included file in the child theme’s functions.php?
- Add Adsense code between job listings – wp job manager plugin
- update_post_meta is Updating with two page id
- If is_single in functions.php
- How to conditionally add a widget via a hook in functions.php
- How to place a div inside a function that creates a div
- Changing the text of Upload/Insert on Posts and Pages Screen
- How to add or delete default value theme options while activate and deactivate theme
- WordPress comment processing . Default unapproved comments detection before posting
- Warning at top of website & top menu gone
- Save_post – Warning: Cannot modify header information
- How to use WP conditional tag in a functions.php with OCEANWP Theme?
- custom error message for empty username and password using authenticate filter not working
- Get post_author email for Zapier Integration
- How can I stop the hook from breaking the login/logout function?
- True email confirmation for registration (keeping unvalidated users from user table)
- $content is empty while using DOMDocument
- WordPress hooks to call a function inside a construct
- WordPress undefined function error on using add_action() in functions.php
- How to echo the translated custom field?
- save_post hook – headers already sent?
- Init hook for header send
- How accomplish modification the_content if home/start page?
- Add custom fields after post/page title
- Force resize for all video content
- Unhook the comment form in Buddypress
- Why functions metaboxes is causing White Screen in Admin [closed]
- How do I add functionality to images?
- How to hook wp_mail to add a custom email as BCC for each sent email?
- Creating mixture of shortcodes to use in the visual/text editor
- image_size with respect to aspect ratios
- Get category of post inside save_post hook
- Create section wit form