I thought of creating a shortcode to insert into the content of the
post, but while I can create one that includes just text, when I put
the above code into the shortcode.php file, it breaks.
Your code outputs data to the screen. You can’t do that with filters like the_content
. You need to concatenate a string and return it. Something like:
function the_content_cb($content) {
$str="";
if( get_field('kindle') ) {
$str .= '<a href="'.get_field('kindle').'"><img src="url.com"></a>';
}
if( get_field('nook') ) {
$str .= '<a href="'.get_field('nook').'"><img src="url.com"></a>';
}
return $content.$str;
}
Note: the_field()
is a plugin function– Advanced Custom Fields–, as is get_field()
.
Related Posts:
- Display all values of custom a field created with ACF on a page
- If Custom Field is empty don’t display div
- Unique key for each row in a repeater field
- How to Explode a Textarea Field and Echo each line separately, wrapped with HTML
- Importing hard coded custom field into acf field
- Showing content from one page on another
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- How to use thumbnail size of image if I’m only using src to get image
- Redirect to another page using contact form 7? [closed]
- Get URL from shortcode tag
- Advanced Custom Fields – display label and value only if value entered
- Only first shortcode gets executed
- Create a WordPress shortcode using PHP [duplicate]
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Creating an image from a custom field
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- Can ‘Custom Field’ data be inserted into this Short Code?
- Delete images from media library when user deletes an image from ACF Gallery
- Updating Metadata with Shortcode
- How to Create custom block for displaying information in content section which act like shortcode
- Block error message in foreach loop when looping through ACF field
- Query on a repeater date (acf)
- ACF – Can’t get custom post type by taxonomy
- Advanced Custom Forms PHP formatting for do_shortcode
- How to output values from a loop into a javascript array
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- Custom fields changes the formatting of metabox input
- How can I put a custom field as the link of a button shortcode?
- Custom field within shortcode
- ACF Date fileds to Age Convert [closed]
- Shortcode Displays 2 times
- How to execute a shortcode within a custom field?
- ACF number less than comparison not working
- Conditionally loading JavaScript based on the Advanced Custom Fields in the post
- Custom Meta Field – Youtube embed
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- How to return a string that has a variable inside in a shortcode?
- Passing a shortcode attribute to a sub-function
- Print html when custom field has value inside while loop
- WordPress Wysiwyg Content not being displayed
- is_page “range” for if statement?
- How can I generate random numbers inside my shortcodes on each implementation?
- Sum custom field values of particular taxonomy
- Different loop output every x posts in custom post type
- Showing a different gallery in a seperate post
- Saving an array of dynamic repeater data as post_meta
- WordPress Shortcodes.. printf is outputting a random number… Can’t figure out WHY?
- How can I add extra word in permalink when someone click download button?
- Seach custom post type posts only by meta fields?
- Slick + PHP + ACF + JQuery slide reveal not working
- Displaying recent posts on static page with template-part via shortcode
- conditional logic for front-end custom field edits
- Displaying custom field according to date
- Which PHP page is the Default Posts Page
- List taxonomy term slugs within shortcode (do_shortcode)
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- How to create an ACF shortcode with Repeater Field in WordPress? [duplicate]
- How to show/hide php table rows based on the content of custom fields
- how to get serialized post meta
- Can I set up a hover animation in CSS depending on a PHP conditional?
- Conditional multidimensional arrays and array_map
- Shortcode to pull posts
- Help Fallback (thumbnail)
- How to return a string that has a jQuery and Ajax inside in a shortcode?
- Conditional featured image with youtube thumbnail
- ACF Unexpected T_CONSTANT_ENCAPSED_STRING [closed]
- Change Spaces to Dashes?
- Get All In One SEO Pack to use custom field instead of Content
- Problems updating nested ACF field groups
- Create shortcode for metabox gallery
- Setting up a cron job to auto update a custom field
- couldnt show short code atts in category
- ACF Gallery field images donwload
- overwrite wordpress gallery with custom gallery shortcode
- ACF under category name in shop page [closed]
- Trying to retrieve meta values from three different meta keys and display in rows
- WP post meta – for loop inside for loop
- ACF background-color per post in a WordPress loop
- Store custom field’s multiple values in one user meta key
- WooCommerce multiple custom fields code
- Open/closed function [closed]
- What is wrong with this shortcode? to include external php file in WordPress posts
- Need to Echo A Url path to show on a wordpress page
- WP_query meta_query slow with OR and DATES
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
- meta field for numerous links
- Is there a way to have chunks of a page’s content expire?
- Formatting Shortcode to Display in Visual Mode
- divide custom field values in div every two values
- Showing custom field contents without listing description
- How to exclude post from being queried based on custom meta value
- Overwriting a Shortcode
- Search result page – display values from the result’s metaboxes
- A next page function with shortcode?
- using a shortcode in a hyperlink
- Display total count of products in orders of a specific order status
- advanced custom fields: repeater field within conditional statement [closed]
- Search custom post type posts only by meta fields?
- How to pass value to add_filter wpcf7_form_tag from another function?
- How to edit a widget code?