If it was me I’d not echo the text I’d make it a variable e.g. $additional_text = ""
then at the end of the function return $additional_text;
.
if (have_posts()) : while (have_posts()) : the_post();
$additional_text="<div class="timeline">";
$additional_text .= '<a href="';
$additional_text .= the_permalink();
$additional_text .= '"><h3>';
$additional_text .= the_title();
$additional_text .= '</h3></a>';
$additional_text .= '</div>';
endwhile; else:
$additional_text="No Posts Sorry.";
endif;
Then, when you call the function it’s going to get the variable as opposed to writing to the page.
Related Posts:
- Passing values from a widget to a function within a plugin
- Regex works in regexr, but not if I filter content [closed]
- Problem in outputting shortcode
- Best way of passing PHP variable between partials?
- Remove Actions/Filters added via Anonymous Functions
- Add class to menu items of one specific menu (nav_menu_css_class)
- How to influence the information displayed on widget inside wp-admin
- How to restrict actions and filters “properly” by conditions
- Filter the query ONLY for the search results page
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- Using add_filter() in Widgets
- Customize WordPress Media Manager – Media Window
- Is it possible to use a forgot password url filter?
- Wrap gutenberg block ‘div’ in other elements/extra HTML
- Remove Page Title from Static Frontpage
- Edit the_content function
- Default or Preset Content for Custom Post Types
- Override a class function to include a custom template
- Make WordPress size and name images for Retina.js
- Pinterest Integration Using functions.php
- Exclude Empty Child Categories in Menu
- add_filter priority problem
- Clean-up script tags
- How to use IF Statement in WordPress?
- Gravity Forms field entries into wp_query loop [closed]
- Post Pagination Showing Same Posts Every Page
- modify a function filter
- Super simple shortcode not working
- How would go about if I just want a temporary function?
- Generating rel=prev and rel=next only on wordpress categories
- How to make applyFilters function return false via functions.php
- Accepted arguments value in hook functions
- Get current page_id before loop, in functions.php
- Which action hook to use for function?
- str_replace function in theme
- Last updated date function
- Modify a function without editing template
- How to add nav menu items to a specific position within a menu
- Using $themename Variables
- Disable auto-resizing of uploaded images, but only for certain filename
- Filter out other users comments. Visualize only own comments and editor role users’ comments
- Get Current Post ID in functions php, meta query filter
- Output and filter data from a XML url
- Add to cart php not working [closed]
- Is possible add icon in title posts only in specific tag?
- What did I do wrong in my functions code, that will not change the “Get New Password” text to “Send It”?
- create filter in functions.php
- Insert image in WordPress with HTML5 tag and caption function
- How to construct function for applying filter?
- Adding an external HTML link to a post thumbnail
- woocommerce change currency per category [closed]
- Add Element as a Filter to the_content
- Make wp_link_pages() suitable for Twitter Bootstrap markup
- Setting a default text for excerpts of a particular category
- Can’t properly set the_title add_filter to show short_URL
- Add_filter when value is no variable?
- (Woocommerce) Order by price when entering specific category
- Define PHP variable from a seperate API if statement
- How to edit classes in body tag?
- Tags break custom Excerpt function
- problem loading stylesheets to wp_head dynamically
- Possible to hook into Media Library preview File column and use a custom image?
- Undefined variable error in new function
- How to display the_archive_title() and the_archive_description() – “weird” interaction
- How to add custom li item to wordpress menu
- How to edit/replace Parent functions.php function in Child Theme to add “Walker” class
- Functions Filter Question [closed]
- Is it possible to use add_filter in an included file in the child theme’s functions.php?
- Insert Content Before div#main from the functions.php File
- add_menu_page() with variable function
- Changing the text of Upload/Insert on Posts and Pages Screen
- Conditional custom menu?
- Do I Need to Prefix Variables Inside Functions?
- Get URLs for AJAX Filter Checkboxes WordPress
- Updating custom query var with multiple values
- How to display an image before title text in menu items
- Adding custom social icons to the social media icon block in the Gutenberg editor?
- Change Page Title
- Filter works on last selection but no others
- post value to function with Ajax and jQuery
- Getting value of variable from functions.php and debugging it
- Pass post ID from archive template to functions file
- How to access custom class methods from any include without using global
- Prevent function from triggering on current page
- Assign IDs to headings in ACF using functions.php
- Redirect specific author posts to another url
- $content is empty while using DOMDocument
- What is best practices to move the following code into a function?
- Best way to add image to recent posts widget?
- previous_post_link inside of a function?
- Search and Replace Script Loader in Head Only Works in Footer
- Setting a cookie in functions.php and it gets deleted when working on an other function
- getExcerpt: Make ellipsis appear only if character limit is reached
- How to Add A Rel Filter to All Links?
- Print all inline styles to head
- child_of not working while searching
- Function Reference for custom link in Admin Menu Management Page
- How to Insert A List of Posts in A Category Written by the Author into the Author Archive
- Integrating custom API for post content into Admin interface & Public Website [closed]
- function to show youtube videos within excerpt – if condition and apply_filters