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,665 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8 votes
1 answer
654 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 -...
danny471's user avatar
  • 191
6 votes
0 answers
246 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 ...
public9nf's user avatar
  • 386
4 votes
1 answer
347 views

Adding custom social icons to the social media icon block in the Gutenberg editor?

In wp-includes/blocks/social-link.php there is a function which seems to setup all the selectable icons in an array together with their names and their SVG code (lookie here on GitHub) Is there a way ...
cinquecentooo's user avatar
4 votes
1 answer
5k 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/...
Dougless's user avatar
4 votes
4 answers
314 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']) && $...
DamithRuwantha's user avatar
4 votes
0 answers
89 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 ...
tibewww's user avatar
  • 297
3 votes
1 answer
94 views

Changing a function in function.php to a shortcode - for listing categories of only a certain post type

I'm trying to create a shortcode that can display a list of categories. However, it should: First, limit the results to a specific post type (based on shortcode usage) then check to see if category ...
Tako Bubble's user avatar
3 votes
0 answers
343 views

Remove elementor header and display default theme header

I am using Elementor pro and I am using Tabor wordpress theme(Here theme link: https://themebeans.com/themes/tabor/). I create custom footer within elementor pro and I noticed that the default theme ...
Mohammed Nabi's user avatar
3 votes
0 answers
911 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 ...
Flint's user avatar
  • 43
3 votes
0 answers
1k views

Is it possible to intercept all ajax requests and get the parameters and the returns?

Is there any hook that always goes through it, where I can see all the requests, and also the returns after the "action" that is executed? I need to intercept all requests, including requests from ...
rafaelfndev's user avatar
3 votes
0 answers
74 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 ...
Aravona's user avatar
  • 585
3 votes
0 answers
54 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 ...
joq3's user avatar
  • 371
3 votes
0 answers
1k 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 ...
Archangel17's user avatar
3 votes
0 answers
38 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 ...
Eager2Learn's user avatar
3 votes
1 answer
176 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 ...
Guenfood's user avatar
3 votes
0 answers
5k 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 ...
Jake's user avatar
  • 250
3 votes
2 answers
5k views

add a function to submit options.php

I have a form which does <form method="post" action="options.php"> ......... <input type="submit" class="button-primary" value="<?php _e( 'Save changes', 'bsp_style_settings' ); ?>" /&...
Robin W's user avatar
  • 31
3 votes
1 answer
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 ...
mcography's user avatar
  • 363
3 votes
2 answers
550 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 ...
Libin's user avatar
  • 276
2 votes
1 answer
33 views

Is it possible to use a post name in a custom post slug?

So I have custom post type called Lessons and I am using something like this for the slug register_post_type( 'Lessons', // CPT Options array( 'labels' => array( ...
Zarko Zivkovic's user avatar
2 votes
0 answers
23 views

How do I stylize selected comments?

I built my own theme from scratch, which has worked well for years, but I'm very rusty now on how I did it, and I could do with some help with my re-learning process. When certain people comment (and ...
Chris Rand's user avatar
2 votes
1 answer
156 views

Using a function to change favorites listing

Sorry - total newbie here with Wordpress development. I have the following plugin installed https://favoriteposts.com/ and it allows you to change the default output of the users favorites by using ...
Ashley Young's user avatar
2 votes
0 answers
162 views

How to debug error message: Cannot modify header information

I'm experiencing some wierdness with a custom theme in WooCommerce. I know that WooCommerce is off-topic, but while debugging it, I've figured out that it most likely is another plugin, that is the ...
Zeth's user avatar
  • 858
2 votes
0 answers
62 views

Disable shortlinks like ?p=1234 to prevent scraping

I have a site with several thousand public pages that use randomly generated slugs for their pretty urls. The content is public in the sense that if someone knows the URL, they can see the content. I'...
Alex Wright's user avatar
2 votes
0 answers
236 views

Override Plugin Script Fucnction in Wordpress

I don't know how to remove a specific function from a plugin. My plugin is Photo-gallery. I want to remove this function: function spider_createpopup(url, current_view, width, height, duration, ...
Ioflvoe89's user avatar
2 votes
1 answer
665 views

Custom roles can't access to wp-admin

i'm trying to create a custom role, very similar to admin but without the capabilities to edit/delete plugins. Since i don't wont to use plugin for that i've edited the functions.php file adding ...
Jack's user avatar
  • 21
2 votes
0 answers
157 views

Redirect a list of URLs to another URL, using functions.php

What I wish to do I have a number of Wordpress URLs I need to redirect, along with a 301 permanent redirect header being sent to browser. The URLs to redirect are: https://www.mydomain.com.au/...
omega33's user avatar
  • 354
2 votes
0 answers
180 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 ); $...
Reto Schneebeli's user avatar
2 votes
0 answers
240 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( '...
Patrick's user avatar
  • 21
2 votes
3 answers
3k views

How to specify which Gutenberg blocks are available in the editor for a page template

Using an example given here: enter link description here I've successfully been able to restrict the block types available globally or by post type (eg: page). But what I really would like to do is ...
UntitledGraphic's user avatar
2 votes
2 answers
1k views

Change links automatically to affiliate links

My goal: I want external links to shops I'm affiliated with (for example amazon) to automatically get the affiliate ID attached to it. Example: link I put in my blog post editor https://www.amazon....
Alina's user avatar
  • 21
2 votes
0 answers
265 views

Wordpress Content Security Policy and Subresource Integrity

I have tested my website at https://observatory.mozilla.org/ and I receive the following two errors: Content Security Policy -25 Content Security Policy (CSP) header not implemented Subresource ...
Dario B.'s user avatar
  • 155
2 votes
0 answers
53 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="...
Tejinder's user avatar
2 votes
0 answers
346 views

Make Categories a Dropdown Menu in Media Library

I would like the categories menu to appear as a drop-down in both the list mode and grid mode view of the Wordpress media library. As of now, it only appears as a drop-down in list mode. List Mode - ...
BlueHelmet's user avatar
2 votes
0 answers
389 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 ....
Jay Caetano's user avatar
2 votes
1 answer
204 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 ...
Samuel's user avatar
  • 344
2 votes
0 answers
729 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 ...
jHaury's user avatar
  • 21
2 votes
0 answers
943 views

How do I create a function that simulate the click on Update button for all posts?

I made a child function.php with this code. All new posts will automatically use the attachment id for the image I have uploaded to my Media Library. function wpsites_auto_set_featured_image() { ...
Kees Jansen's user avatar
2 votes
0 answers
1k 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 (...
Влад's user avatar
2 votes
0 answers
89 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 ...
poncho's user avatar
  • 121
2 votes
1 answer
556 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-&...
parisa's user avatar
  • 21
2 votes
1 answer
57 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 ...
JGallardo's user avatar
  • 194
2 votes
0 answers
2k 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 ...
bdestrempes's user avatar
2 votes
0 answers
919 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, ...
user2882154's user avatar
2 votes
0 answers
803 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 ...
Andrew W.'s user avatar
2 votes
0 answers
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 ...
Drakes's user avatar
  • 143
2 votes
1 answer
263 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. ...
Mike's user avatar
  • 21
2 votes
0 answers
2k 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 ...
themich's user avatar
  • 21
2 votes
0 answers
1k 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 ...
E. Fitzpatrick's user avatar
2 votes
0 answers
195 views

Woocommerce Storefront WordPress Ignore Media Gallery Images and use External 3rd Party Host

OK, firstly we have done this before using Magento and it worked well, but with WordPress? Well, here is the problem and the plan... The Problem For a few reasons we wish to use a 3rd Party host for ...
ipagedesigner's user avatar

1
2 3 4 5
34