add-filter

Adding html to WooCommerce Store Notice using filters

与世无争的帅哥 提交于 2021-02-08 09:27:06
问题 I am trying to add a div wrapper around my WooCommerce Store Notice using a filter. And I also want to replace the dismiss link with a close icon. This is what I have so far and it doesn't really work how I want it to; add_filter('woocommerce_demo_store', 'demo_store_filter'); function demo_store_filter($text){ return str_replace( '<p class="woocommerce-store-notice demo_store">', '<div class="hello"><p class="woocommerce-store-notice demo_store"></p></div>', $text); } Here is the default

Rename the images in wordpress on upload for a specific post type

99封情书 提交于 2020-12-13 03:13:01
问题 as you can see this code to rename images by post title works fine. even with several posts with the same title. it just puts the numbers: image, image1, image2, image3 .. etc /*Renaming attachment files to the post title*/ function file_renamer( $filename ) { $info = pathinfo( $filename ); $ext = empty( $info['extension'] ) ? '' : '.' . $info['extension']; $name = basename( $filename, $ext ); if( $post_id = array_key_exists("post_id", $_POST) ? $_POST["post_id"] : null) { if($post = get_post

Showing posts between a certain date range

依然范特西╮ 提交于 2019-12-23 12:28:27
问题 Trying to display my custom post types for specific date ranges. I want to show posts only within a certain month. I know I need to hook into the posts_where filter, but I can not figure out how to pass arguments to this function, as I need to pass the date range. I have seen plenty of examples of how to alter the WHERE clause to take a date range, but only when static. I need to do the following: add_filter('posts_where', 'my_custom_where', '', '04/2011'); //pass my date to the filter

How to replace meta title and meta description in wordpress?

雨燕双飞 提交于 2019-12-23 05:09:30
问题 Sorry if my question was basic or stupid but please help me to solve this issue. I'm trying to change <title> and <meta name="description" > tags dynamically in wordpress. so this is what I tried in function.php file. function changeMeta_2(){ global $wpdb; $cur_url = $_SERVER['REQUEST_URI']; $basename = pathinfo($cur_url); $ebasename = $basename['filename']; if(is_numeric($ebasename)) { $url = explode('/', $basename['dirname']); $basename = explode('.', $url[count($url)-2]); $ebasename =

wordpress bloginfo filter name and description

孤人 提交于 2019-12-13 05:16:12
问题 I was trying to edit my wordpress site name and description, I got that I have to add a filter plugin like so: add_filter( 'bloginfo', 'My_function_name', 10, 2 ); . It works, but I can't understand why we have to add the 10, 2 parameters? and which values it belongs to? Also there wasn't enough information in codex.wordpress.org Here is my working plugin : function edit_bloginfo($text,$show ){ if (isset($_COOKIE['switch_language'])) { if($show == 'description'){ $text = 'New description'; }

Fatal error: Call to undefined function add_filter() in index.php in Wordpress

倖福魔咒の 提交于 2019-12-11 18:01:14
问题 I want to change my wordpress theme dynamically by user browser. So I found this code on the net and added it to my index.php file add_filter('template', 'switch_theme_by_browser'); add_filter('stylesheet', 'switch_theme_by_browser'); function switch_theme_by_browser($theme) { $browser = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/MSIE/i',$browser) && !preg_match('/Opera/i',$browser)) { $theme = "twentyeleven"; } elseif(preg_match('/Firefox/i',$browser)) { $theme = "twentyten"; } elseif(preg

Difference between add_filter versus add_action

泪湿孤枕 提交于 2019-12-10 13:26:56
问题 I was looking over my functions.php and wondering why CODE A uses add_action while CODE B uses add_filter ? The main goal of CODE A is to both include and exclude specific categories. The main goal of CODE B is to exclude specific categories. Is it correct to use add_action for CODE A and add_filter for CODE B? CODE A: Display specific category (called "featured") for homepage, instead of "the most recent posts" function featured_category( $query ) { if ( $query->is_home() && $query->is_main

Wordpress, add_filter, get_search_form

余生长醉 提交于 2019-12-08 07:44:56
问题 I'm trying to replace the search form by my own. An example plugin: <?php /* Author: whatever Plugin Name: Some Name Plugin URI: Text Domain: some-domain Version: 1.0 */ function custom_search($form) { $form = "testing<form method = 'get' id = 'searchform' action = ' ".site_url()." ' >"; $form .= "<div><label class = 'hidden' for='s'>". __("Search for: ") . "</label>"; $form .= "<input type = 'text' value=' ". esc_attr(apply_filters('the_search_query', get_search_query())) ." ' name='s' id='s

wordpress posts_orderby filter with custom table in plugin

北慕城南 提交于 2019-12-08 05:26:30
问题 I'm developing a Wordpress plugin and need to order the posts of the site with the custom table that I created with my plugin. I don't want to alter the code within the theme so I found on codex the filters posts_orderby and posts_join (found here: https://codex.wordpress.org/Custom_Queries). The custom table have these values: ID slug price and in the plugin file where I added these lines: add_filter('posts_orderby','custom_orderby'); add_filter('posts_join','custom_join'); function custom

wordpress posts_orderby filter with custom table in plugin

风格不统一 提交于 2019-12-06 17:05:43
I'm developing a Wordpress plugin and need to order the posts of the site with the custom table that I created with my plugin. I don't want to alter the code within the theme so I found on codex the filters posts_orderby and posts_join (found here: https://codex.wordpress.org/Custom_Queries ). The custom table have these values: ID slug price and in the plugin file where I added these lines: add_filter('posts_orderby','custom_orderby'); add_filter('posts_join','custom_join'); function custom_join($join){ global $wpdb; $customTable = $wpdb->prefix.'custom_table'; if(!is_admin()){ $join .= "