Questions tagged [functions]

A function is a sequence of program instructions that perform a specific task. It is packaged as a unit that can be used wherever the according task should be performed.

1,311 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8
votes
1answer
188 views

Prevent “main” WPMU site_url() being returned in functions

I've noticed that in a WordPress MU install with domain mapping enabled, some functions return URIs that don't use the current WPMU site's primary domain name which possibly means they are "WPMU ...
6
votes
0answers
364 views

static variable loop not working in Wordpress

I have a function in my wordpress theme that deletes the first embedded video in a video post. See code below. This is in the functions.php file. /* - function that hides first video in post content -...
4
votes
0answers
208 views

Customize WordPress Media Manager - Media Window

Im trying to customize the wordpress media manager "add media" window to get it as simple as possible to use. So i want to disable/ hide the following fields/ functions because i dont need some or ...
3
votes
0answers
40 views

Get widget settings function?

I am using this to find if a new widget has been added or removed from my site: serialize(retrieve_widgets()); Works great for added or removed widgets. But it doesn't detect if a widget setting has ...
3
votes
0answers
652 views

Updating users_can_register option?

I have a custom setting page, where i have a radio to Enable or Disable Registration then try to update the wpoption (users_can_register). Screenshot: I've tried both true/false & 1/0 but it ...
3
votes
0answers
78 views

my function doesn't return my post from today

I'm using gravity form to create some custom post type - as events. Everything is working great, There is some date field to setup the event from x to y date. ALl of this working great. However, I ...
3
votes
0answers
37 views

Date/time limitation of posts where function must be executed

I have this piece of function in my functions.php file: function user_content_replace($content) { $sentences_per_paragraph = 3; // settings $pattern = '~(?<=[.?!…])\s+~'; // some punctuation and ...
3
votes
1answer
151 views

Function to Download External Images to My Site

I display images on my site from other sites. The URL is saved in a custom field named couv. I would like to download these pictures on to my site and create a new custom field with the new value ...
2
votes
0answers
39 views

How to Replace Words with Hypertext Link But Ignore Previously Existed Links?

Auto-linking for "selected words" in the_content I am currently using the following code: function wp_affiliate_links($text){ $replace = array( '/ example /' => ' <a rel="nofollow" href="...
2
votes
0answers
116 views

Contact Form 7 - Delay auto responds

I'm looking for a way to delay the auto response (mail_2) from Contact Form 7 for 2 days. But I have no clue how to tackle it. I hope you have an idea. I'm using the following code in functions.php ...
2
votes
0answers
36 views

How to find out what blocks are added by a plugin

I am creating a plugin, which adds a number of blocks defined by JS/PHP as per Gutenberg documentation. I want to display these block names on an admin page. Is there a hook or function I can use ...
2
votes
0answers
561 views

Override woocommerce wc-class function

I'm not good in WP and plugins and will need some help here. I've read that is possible to alter some WC core function with filters and action but probably I didn't understand this correctly. I want ...
2
votes
1answer
263 views

Hide some items from Screen options in dashboard for products

I am trying to unset/hide some options in dashboard. I am trying it for products screen. Here is the screenshot Here is the code i tried to hide SKU /** Hide Dashboard widget by default via Screen ...
2
votes
0answers
213 views

How to change the page break <!--nextpage--> URL from ../post/2 to …/post/page2/

I am referencing the WP codex here: https://codex.wordpress.org/Styling_Page-Links but cannot find a way to customize the post URL for page break ( ) feature. For exmaple: instead of the traditional ....
2
votes
1answer
3k views

AJAX handler throws 400 (Bad request) - why?

I am trying to apply a "Load more posts" function to a post loop, but I am dealing with a 400 Bad request, when admin-ajax.php is referred to. The reference I used is this - https://rudrastyh.com/...
2
votes
1answer
125 views

password protected post policy

I'm looking for a way to add policy about POST password. Password specifications : 12 characters in length, 1 uppercase letter, 1 lowercase letter, 1 number, and 1 special character. Is ...
2
votes
1answer
3k views

Woocommerce auto cancel On-Hold after X days

I have searched high and low but with no resolve. So we developed a custom "bacs" type gateway for our site. Here in Brazil you can pay via a bank billet. The billet usually has an expiration date for ...
2
votes
0answers
470 views

Search user metadata with checkboxes via ajax (almost working)

I have created an ajax search form following some tutorials online, it is working but not exactly how I need it to. Here is where I got the search from. I have US states setup as a user meta field ...
2
votes
0answers
329 views

How to use max and min values of custom fields

How to use max and min values of custom fields (created via ACF, repeater type)? For axample, I've custom post type 'auto' and there are a lot of models. Each post(model) has few values of price (...
2
votes
0answers
50 views

Trying to inject twitter metadata into <head> using wp_head action in functions.php - get_the_excerpt() returns null

So I followed the "Add Twitter Cards without plugins" this tutorial for how to add twitter metatags into the header using the wp_head method. I have pretty much taken the code as is, and put it in ...
2
votes
1answer
280 views

How to make thumbnail image fit into a div where image dimentions are completely different?

I defined a div which is 200px * 200px for my thumbnails using the code below in my index.php file: <ul> <?php $my_query = new WP_Query('showposts=10&cat=3'); while ($my_query-&...
2
votes
1answer
44 views

Hiding posts in a list from specified categories

Question How can I modify this code to not show posts from new categories that we just added. I searched other similar answers on this site [such as: Exclude category on blog list page ] but not ...
2
votes
1answer
774 views

Generating Responsive Background Image Sizes in PHP

Im trying to generate responsive background images for my page header, using a modified version of this gist, but I cant get it to work correctly, and Im not sure if the issue is with ...
2
votes
0answers
1k views

Logging in redirects to correct page but shows logged out content until forced refresh

I'm trying to change some of the content being shown to viewers based on whether they are logged in or not. I'm using the is_user_logged_in() function in my child theme's functions.php to replace the ...
2
votes
0answers
678 views

woocommerce target button with class after ajax update

I'm working on a eshop using woocommerce. I have an add to cart button with class "single_add_to_cart_button", and a variations select list with 3 sizes. When I select a size which is unavailable, ...
2
votes
0answers
622 views

Function to “Press Update Button” on all posts

tl;dr - I need the equivalent of pressing the "Update" button on many/all posts, without having to manually open each post and press "Update". I'm bulk importing from a CSV into WooCommerce, which is ...
2
votes
4answers
83 views

What is the Difference between directly call a function and call a function using add_action?

What is the difference between following two codes? (Directly call a function and call a function using add_action) function pp_submit__link_form(){ if(isset( $_POST['action']) && $...
2
votes
0answers
2k views

Move jQuery and Migrate to footer?

I've seen this answer, but I'd like to move Migrate as well. I'm trying to move both jQuery and Migrate to the footer and change the jQuery to the CDN version. Here is the failed code I've tried (Why ...
2
votes
0answers
3k views

Force update all posts in custom post type, no content changes

I have imported data from a custom post type that has location data for a map plugin (Progress Map). I have about 500+ posts each with different location data. For some reason the location data isn't ...
2
votes
1answer
113 views

How to use IF Statement in WordPress?

I can't see how to correctly use the PHP if statement in my filter function below. This code works perfectly if all (3) of my $_POST inputs have values however it has a fatal error if any are empty. ...
2
votes
0answers
1k views

bulk change of image setting “link to” to “link to: image url ”

i want every image present on my wordpress site with setting "link to: none" or "link to: post url" became in "link to :image url" ho make this for old post and for new post ? i tried this code in ...
2
votes
0answers
881 views

Change logo based on incoming domain

The agency I work for are trying to get a client's logo to change based upon the incoming URL. Now, we have 4 different URLs, therefore 4 different logos. Currently, we are using an if/else ...
2
votes
1answer
4k views

Change meta tags programatically

Is there a way to change the meta tags not in the head but in a template file through code? I would like to change the meta tags <meta property="og:title" content="title" /> <meta ...
2
votes
0answers
1k views

Overwrite Parent Theme add_image_size in Child Theme

I'm using a child theme of a parent theme. Now on my parent theme, theveloper adds some custom image sizes like this - if ( function_exists( 'add_image_size' ) ) { add_image_size( '...
2
votes
1answer
2k views

Custom wp_trim_words() function not trimming right

I have this custom wp_trim_words() function set to give me excerpts of only 20 words, and for the most part, it works fine. Except for some reason, on posts that contain lists, it outputs way more ...
2
votes
2answers
101 views

How to show in search results posts with a particular tag in a particular category?

As the home page of my blog I've a static page. There I want to show the navigation of the site. Category1 Sub-Category1 tag1, tag2, tag3 Category1 Sub-Category2 tag1, tag2, tag3 Category2 Sub-...
2
votes
0answers
1k views

jQuery Plugin to use Wordpress functions in AJAX request

I'm using Chained Selects jQuery Plugin to create multiple chained selection fields. I'm using the remote version of the plugin to build the related options by means of AJAX request from a separate ...
2
votes
1answer
145 views

How can I list random authors from current post category?

The following lists authors of the current category. But I want this to be a list of 6 random authors from current post category. foreach((get_the_category()) as $category) { $postcat= $category-&...
2
votes
4answers
2k views

Using plugin functionality in external php script not working

I am encountering a strange problem which I couldn't solve so far. I'm calling a .php script via cronjob (Debian/GNU Linux). To use wordpress functionailty I added: define('WP_USE_THEMES', false); ...
2
votes
2answers
306 views

Find first image on paginated post for Pinterest

I've been looking for days, yet can't find a good answer. Perhaps the SE crowd can be of assistance. Any help is much appreciated. I am using a custom-coded pinterest button included on posts that ...
2
votes
1answer
48 views

How to remove the embed_footer?

I'm trying to remove the entire embed_footer from WordPress embedded posts. By adding the following code in the functions.php, I was able to remove the site title and comments icon. But still, the ...
1
vote
0answers
12 views

Wordpress if (is_page) translation on certain page

Hy there i have the following code for custom translations there are missing. function translate_text( $translated ) { $translated = str_ireplace( 'All Ratings', 'Alle Bewertug', $translated ); $...
1
vote
1answer
8 views

Display a specific category of products in shop page and disable code for specific actions

I want to display a specific category of products on the top page of the shop page. This was achieved with the code below. However, with this code, when searching for products from the search console, ...
1
vote
0answers
10 views

WordPress Menuing Question :focus

I'm using the following script in the WordPress functions.php file to disable top level parent items when they have a submenu. It works perfectly, but I need to it actually work like this: If ...
1
vote
0answers
12 views

IF Statement on Button to make it complete and “uncomplete” based on user action / click

I am just working on an LMS and there is a php if statement, that from as much as i can read, says if the button is clicked return this state e.g. set the button and lesson as Completed (default state ...
1
vote
0answers
9 views

Create a new query in function.php to filter blog posts

My goal is to filter blog posts (those which are requested in the blog page - Reading settings) depending on an expiration date, and then to change their category depending on a choosen future ...
1
vote
0answers
23 views

Woocommerce related product text

Hi guys im currently using this in my function.php // Change WooCommerce "Related products" text add_filter('gettext', 'change_rp_text', 10, 3); add_filter('ngettext', 'change_rp_text', ...
1
vote
0answers
10 views

How to add SVG icon above product tab title

I used the following code to create custom product tabs (woocommerce), and now I was wondering if I can add an SVG icon above the tab title. My code for a custom product tab: add_filter( '...
1
vote
0answers
12 views

Filter out other users comments. Visualize only own comments and editor role users' comments

I have a similar request as per question but I am totally not into php and would not know where to start to make such edits based on the answer provided. Would be great if anyone could help here. ...
1
vote
1answer
27 views

Get Current Post ID in functions php, meta query filter

How do I get the Current post ID in functions php when creating an meta query filter? I've made many attempts but all return Null. The filter works as expected when I manually input a number, but I ...

1
2 3 4 5
27