I would like to remove the '[...]' from the RSS feed widget in my Wordpress site and replace it with '...'.
I have tried adding the following to functions:
function replace_ellipsis($text) {
$return = str_replace('[...]', '...', $text);
return $return;
}
add_filter('get_the_excerpt', 'replace_ellipsis');
However, this does not affect the widget.
Any help?
This is defined in v3.4.2 in wp-includes/default-widgets.php, lines 848 - 862. The only function that can be hooked into that I can see is esc_html, so here's what I use:
add_filter('esc_html', 'transform_ellipsis');
function transform_ellipsis($s_html) {
return str_replace(' […]', '…', $s_html);
}
It says here: http://codex.wordpress.org/Function_Reference/the_excerpt_rss that it hooks to 'the_excerpt_rss', so perhaps this will work:
function new_excerpt_more( $excerpt ) {
return str_replace( '[...]', '...', $excerpt );
}
add_filter( 'the_excerpt_rss', 'new_excerpt_more' );
if that doesn't work, see this page for more ways: http://codex.wordpress.org/Function_Reference/the_excerpt#Remove_.5B....5D_string_using_Filters
Related
What I currently have developed:
http://wordpress.test/hashtag/result/?hashtag=twerk
What I want to achieve:
http://wordpress.test/hashtag/twerk
I have made a custom plugin which currently reads the 'hashtag' (query string) and displays it through my custom shortcode.
/result/ is a static page with the custom shortcode [woink_hashtag_result]. This currently works as intended.
Here is what I've currently produced.
function woinkResult()
{
$return = '<p>' . get_query_var ('hashtag' ) . '</p>';
// Output needs to be return
return $return;
}
add_shortcode('woink_hashtag_result', 'woinkResult');
function pce_register_query_vars ( $vars ) {
$vars[] = 'hashtag';
return $vars;
}
add_filter ( 'query_vars', 'pce_register_query_vars' );
How can I make the url prettier like: http://wordpress.test/hashtag/twerk ?
Thanks if you have made it this far.
I have problem with my woocommerce downloads section on WooCommerce "my account" > "Downloads": On product variations name, there is a <span> html tag that are visible:
I have tried to remove those "span" tags using:
add_filter( 'woocommerce_customer_available_downloads', 'remove_span_dl_name', 10, 7);
function remove_span_dl_name( $download ){
return str_replace( '<span> - </span>', ' - ',$download['download_name']);
}
but it removes all downloads altogether.
And I have also tried to remove those "span" tags using:
add_filter( 'woocommerce_available_download_link', 'remove_span_dl_name', 10, 7);
function remove_span_dl_name( $download ){
return str_replace( '<span> - </span>', ' - ',$download['download_name'] );
}
What is my mistake and how can I get rid of these tags?
The hook woocommerce_available_download_link is included in myaccount/my-downloads.php deprecated template since WooCommerce version 2.6 (the right template file that is used is myaccount/downloads.php).
Now as downloads are loaded through WC_Customer method get_downloadable_products(), you can to use woocommerce_customer_get_downloadable_products filter hook included in this method. Or also woocommerce_customer_available_downloads filter hook too.
To remove tags from product name, you can use str_replace() or much better and efficient strip_tags():
1). First way - Using strip_tags() function:
add_filter( 'woocommerce_customer_get_downloadable_products', 'remove_span_tags_from_product_name' );
// Or also
// add_filter( 'woocommerce_customer_available_downloads', 'remove_span_tags_from_product_name' );
function remove_span_tags_from_product_name( $downloads ){
// Only on my account downloads section
if ( ! is_wc_endpoint_url('downloads') )
return $downloads;
// Loop though downloads
foreach( $downloads as $key => $download ) {
// remove "span" html tags
$downloads[$key]['product_name'] = strip_tags( $download['product_name'] );
}
return $downloads;
}
2). Another way - Using str_replace() function:
add_filter( 'woocommerce_customer_get_downloadable_products', 'remove_span_tags_from_product_name' );
// Or also
// add_filter( 'woocommerce_customer_available_downloads', 'remove_span_tags_from_product_name' );
function remove_span_tags_from_product_name( $downloads ){
// Only on my account downloads section
if ( ! is_wc_endpoint_url('downloads') )
return $downloads;
// Loop though downloads
foreach( $downloads as $key => $download ) {
// remove "span" html tags
$downloads[$key]['product_name'] = str_replace( array('<span>', '</span>'), array('', ''), $download['product_name'] );
}
return $downloads;
}
Code goes in functions.php file of your active child theme (or active theme). Any way should work.
If you want that to work also everywhere ("order view", "Order received", emails notifications), remove:
// Only on my account downloads section
if ( ! is_wc_endpoint_url('downloads') )
return $downloads;
I'm trying to add custom plugin after single post content. I have tried with add_filter and add_action to get my plugin printed out.
if(!defined('ABSPATH')) exit;
function customPlug_plugin_install()
{
}
register_activation_hook(__FILE__, 'customPlug_plugin_install');
function customPlug_plugin_scripts()
{
wp_register_script('customPlug_script', plugin_dir_url(__FILE__), 'js/customplug.js', '1.0', true);
wp_register_script('customPlug_bootstrap_script', plugin_dir_url(__FILE__), 'js/customplug.js', '1.0', true);
wp_register_script('customPlug_script', plugin_dir_url(__FILE__), 'js/customplug.js', '1.0', true);
wp_enqueue_script('customPlug_script');
}
function my_plugin($content) {
$content = "Custom Plugin Content";
return $content;
}
add_action('the_content', 'my_plugin');
However, this is just returning either the plugin content, or the_content if I comment out add_filter or add_action
You're overwriting current content. You should concatenate your content to current content with .
function my_plugin($content)
{
$content. = "Custom Plugin Content";
return $content;
}
I have added a filter on "the_author" to add some html code with author info. However all my HTML is coming under an anchor of author link. For eg:
add_filter( 'the_author', 'myfun');
function myfun( $content ) {
$content.= 'hi';
return $content;
}
Now "Hi" is just a simple text which should not be included in author anchor tag. Please help.
add_filter( 'the_author', 'myfun' );
add_filter( 'get_the_author_display_name', 'myfun' );
function myfun( $name) {
global $post;
if ( $name)
$name.= '</br>hi';
return $name;
}
I can't seem to get my functions to work for changing the excerpt_more filter of the Twenty Eleven parent theme.
I suspect it might actually be add_action( 'after_setup_theme', 'twentyeleven_setup' ); that's the problem, but I've even tried remove_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' ) to get rid Twenty Eleven's function and still my functions aren't changing anything...
Can you help?
Here's the functions.php code in full:
http://pastie.org/3758708
Here's the functions I've added to /mychildtheme/functions.php
function clientname_continue_reading_link() {
return ' ' . __( 'Read more... <span class="meta-nav">→</span>', 'clientname' ) . '';
}
function clientname_auto_excerpt_more( $more ) {
return ' …' . clientname_continue_reading_link();
}
add_filter( 'excerpt_more', 'clientname_auto_excerpt_more' );
Thanks,
Osu
Ok, so after much frustration, I found a solution to this (I thought Child Themes were meant to speed things up!?). I believe this works because 'after_theme_setup' is run once the parent theme has been set up meaning you can remove / override Twenty Eleven's functions at that point.
If I've understood correctly, according to this documentation, the Child Theme is run first, then the parent and then the 'after_theme_setup' bit of code in your Child Theme's functions.php file:
http://codex.wordpress.org/Child_Themes#Using_functions.php
and
http://codex.wordpress.org/Plugin_API/Action_Reference/after_setup_theme
This is what's in my Child Theme's functions.php file, hope this helps someone:
// ------------------------------------------------------------------
// // !AFTER_SETUP_THEME
// ------------------------------------------------------------------
/* Set up actions */
add_action( 'after_setup_theme', 'osu_setup' );
if ( ! function_exists( 'osu_setup' ) ):
function osu_setup() {
// OVERRIDE : SIDEBAR GENERATION FUNCTION - NO WIDGETS FOR THIS SITE
remove_action( 'widgets_init', 'twentyeleven_widgets_init' ); /* Deregister sidebar in parent */
// OVERRIDE : EXCERPT READ MORE LINK FUNCTION
function osu_readon_link() {
return '...' . __( 'Read More...', 'clientname' ) . '';
}
// Function to override
function osu_clientname_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
// $output = trim($output);
$output .= osu_readon_link();
}
return $output;
}
remove_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' );
add_filter( 'get_the_excerpt', 'osu_clientname_custom_excerpt_more' );
remove_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );
add_filter( 'excerpt_more', 'osu_readon_link' );
// OVERRIDE : EXCERPT LENGTH FUNCTION
function osu_clientname_excerpt_length( $length ) {
return 30;
}
remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' );
add_filter( 'excerpt_length', 'osu_clientname_excerpt_length' );
}
endif; // osu_setup
Your own answer is complicating things and really shouldn't be necessary. I couldn't explain the why of my answers, because I found it in another answer. But in any case you can ALWAYS override functions from the parent theme in your child theme, although sometimes indeed you to use the remove_filter() beforehand, OR, like in this case, all you have to do is increase the priority of your added filter, in your case:
add_filter( 'excerpt_more', 'clientname_auto_excerpt_more', 11 );
That should do the trick. If not, increase the number.
Thanks to this answer: