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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
565 views

In WordPress how do you remove render-blocking CSS manually without a plugin?

I want to remove the render-blocking CSS that PageSpeed Insight tells me about. Plugins don't seem to work. To do it manually I gathered that you should add some code to the "functions.php" ...
Zaza Zaza's user avatar
0 votes
0 answers
63 views

Shortcode cannot parse attributes within double quotes. " is becoming ” breaking my shortcode

I made a plugin that creates a shortcode to calculate the time since a particular date in the past. It has two attributes, a date string and units: function timesince_shortcode($atts) { $atts = ...
Sidewinder's user avatar
0 votes
1 answer
277 views

Customize Notification Email Sent to New User When Manually Created by Site Administrator

I am looking to customize the "Login Details" email sent by WP Core when an administrator checks off "Send User Notification" while manually creating a user from /wp-admin/user-new....
Evan Kirschenmann's user avatar
1 vote
2 answers
60 views

How to display *block number* instead *date value* on Wordpress posts?

Ideally, the goal is to show the block number (ie: 782667) instead of the date value (ie: 26 March 2023 4:44PM CT) on all wordpress posts and pages that currently display it. There's maybe a script we ...
SuperAtic's user avatar
  • 149
0 votes
0 answers
56 views

Wordpress enque the same script causes the setInterval not to work

So I created an idle-timeout.js that will check the user total idle time. And I loaded it with admin_enqueue_scripts then after the session timeout the user can re-login again with the popup modal so ...
code.cycling's user avatar
0 votes
1 answer
47 views

Custom HTML structure in customizer not rendring in Browser

$wp_customize->add_section( 'sutta_section', array( 'title' => __( 'Sutta', 'yourtheme' ), 'priority' => 160, )); $wp_customize->add_setting( 'show_sutta', array( 'default' =&...
WordCent's user avatar
  • 1,867
0 votes
1 answer
48 views

add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico

Please Friend all, help me! How add_rewrite_rule in multisite subdomain from images via functions.php not .htaccess My Image Path https://cdn.domain.com/images/site2/favicon.ico But I want change url ...
Muhammad Hasan Bahtiar's user avatar
0 votes
0 answers
43 views

How to store page-{id}.php templates in custom folder

I'm trying to create a custom function on WordPress to store page-{id}.php templates in a folder named "custom-pageid-templates" inside my theme directory. Here's the code I'm using: ...
Robin Alexander's user avatar
0 votes
1 answer
27 views

Wanted to get rid of Paragrapgh tag in submit buttom of the WordPress form

function modify_comment_form_fields($fields){ // Check if $fields is an array if (!is_array($fields)) { return $fields; } ob_start(); $submit_button = ob_get_clean(); $submit_button ...
WordCent's user avatar
  • 1,867
0 votes
0 answers
767 views

Fatal Error: Uncaught ArgumentCountError: Too few arguments to function - on logout of wordpress dashboard

I am getting a fatal error when trying to login to the WP dashboard - and on logout after logging in via the host: Fatal error: Uncaught ArgumentCountError: Too few arguments to function Wpsec\captcha\...
incredibull808's user avatar
0 votes
1 answer
90 views

Link on post title only if post have content

Hello i create an archive.php custom for category-id (category-id.php) and use this code <?php /** * A Simple Category Template */ get_header(); ?> <section id="primary" ...
Scrivere Creativo's user avatar
0 votes
1 answer
40 views

Why is my custom email notification after purchase not sending?

I'm trying to send an email to a specific address (the admin) but online if a customer purchases one of four specific products. I'm using this code in my functions.php in my plugin for the page. But ...
Lisa's user avatar
  • 13
0 votes
1 answer
164 views

How to use shortcode to get the second to newest post?

I've done considerable research, and tried multiple solutions to my task, and currently have found a way but i know it is not the best, so hoping for input to do this better. The task I am using ...
Ben Blue's user avatar
  • 117
0 votes
1 answer
25 views

post_row_actions filter from parent theme not executing in child theme

In functions.php for a theme I include a file that adds functionality to allow the easy duplication of posts - the include file contains the code from this (very useful) webpage. I include it like ...
toby1kenobi's user avatar
3 votes
1 answer
640 views

Loading newest dependency javascript module file in functions.php

Continuing from this question: I have scripts enqueued in functions.php file so scripts load only on certain pages (I cut most of them in code below): add_action( 'template_redirect', 'plugin_is_page' ...
FilipD's user avatar
  • 73
0 votes
0 answers
33 views

Run a function only once when logging into dashboard

I want the Pro version of my plugin to do a version check once when an Administrator logs into the dashboard. At the moment I am connecting to my API using wp_remote_get() in the main plugin file, but ...
Steve's user avatar
  • 297
4 votes
1 answer
271 views

Auto updating JavaScript dependancy in functions.php

I'm enqueuing scripts with dependency in functions.php file like: wp_enqueue_script('ads', get_template_directory_uri() . '/js/ads.js', array( ), '1.6', true); wp_enqueue_script('banners', ...
FilipD's user avatar
  • 73
0 votes
0 answers
63 views

How to save a post to a Custom post type and copy the information to another Custom post type?

I used the Jet Engine plugin to create the first Custom Post Type called registration, the Post Type Slug called registration, and the Rewrite Slug called registration-add. The first Custom Post Type ...
Anderson Viviel's user avatar
0 votes
1 answer
74 views

How to add more than one menu for logged in members?

I have the following code to show different menus to logged in members. I would like to add a second menu to be displayed when logged in, for a total of 3 menus, as there are two different menu areas ...
kerfuffleslop's user avatar
0 votes
2 answers
81 views

Using input_attrs() Multiple Times Within One Customizer Control

Using input_attrs() Multiple Times Within One Customizer Control. I want to be able to use the function input_attrs() https://developer.wordpress.org/reference/classes/wp_customize_control/input_attrs/...
Angel Hess's user avatar
1 vote
1 answer
142 views

Get category of post inside save_post hook

I don't have much experience with hooks in WordPress so i have found a problem who don't look too difficult, but i can't find the answer. In my project i have a metabox who will get the content after ...
Matheus Ribeiro's user avatar
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
0 votes
0 answers
284 views

get page_id in ajax to function in functions.php

Im loading "read more"-content via ajax and json. This works global for all pages. But I need the extra-content only from the current page Im viewing. Now I want to pass the page_id into my ...
hes's user avatar
  • 1
0 votes
2 answers
484 views

How to sort posts alphabetically based on a specific parent category

I'm building out an index page of posts that are grouped under multiple categories, but those categories are all under the same umbrella parent category. I'd like to have these posts displayed ...
jzn110's user avatar
  • 1
4 votes
1 answer
157 views

delete_term is not working properly with add_action()

delete_term is not working, I'm trying to delete term and after I deleted it, it'll also delete the similar term from different a taxonomy based on their slugs here's my code of the delete_term, so in ...
agent abstract's user avatar
0 votes
0 answers
44 views

Product customizing quiz - quiz adding products to the cart

Spend a lot of time on this and my client is getting angry but still no results… Is there any plugin (or solution to use) you know to instantly add product to cart after giving specific answer on a ...
dbamo's user avatar
  • 1
0 votes
0 answers
184 views

Creating posts with php-script + csv

I'm trying to create posts with a Script + CSV. Each row schould create a post, while each column should fill the title/ACF-Fields. $csv_file_path = '/test.csv'; function create_wp_cpt_from_csv() { ...
Dave's user avatar
  • 1
2 votes
1 answer
112 views

Swap Wordpress "Widget Area" based on Page Template

i'm using 3 widget areas in my child theme's footer. i created a secondary custom theme successfully, and am hoping i can simply change those 3 widget area's out in the second theme. "Footer - ...
SyberKnight's user avatar
0 votes
1 answer
22 views

How can I modify or filter this variable in an existing class? (Mai Theme)

I'm trying to utilize existing post-grid functions to show attachment posts but $post_status is hard coded to be either 'publish' or 'private' whereas attachments have a status of inherit. I added '...
fourohfour's user avatar
0 votes
0 answers
26 views

Wordpress Convert queries to slashes using function.php

Please check and explain why this wordpress rewrite rule isn't still working. function myplugin_rewrite_rule() { add_rewrite_rule( '^music/record-year/([^/]*)/?', 'music/?record_year=$matches[1]','...
John Ovye Godwin's user avatar
0 votes
0 answers
19 views

How to change all the urls of the WordPress site?

We have created an online store with WordPress on a domain and now that we have finished testing, we must take it to the final domain. I only need a method to change all the URLs of the site I have ...
Estudiante's user avatar
0 votes
1 answer
195 views

How to overwrite image if it already exists - Wordpress, Gravity form

How do I make the old file replaced when the user uploads a new one? Now the files are named a1.jpg, a2.jpg, a3.jpg. If the user uploads a.jpg, then I want to overwrite the a.jpg that already exists. ...
Masterior'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
0 votes
1 answer
47 views

How to enqueue Bootstrap 4.6 js & css from local files

I currently have Bootstrap 4.6 js and css loading from Bootstrap CDNs in WordPress via wp_enqueue_script and wp_enqueue_style respectively in the functions.php file wp_enqueue_script( 'bootstrap-js', '...
inputforcolor's user avatar
0 votes
1 answer
66 views

woocommerce_sort_product_tabs() expects an array

I am trying to add a custom tab to Woocommerce Product ; I have tried with this code snippet in functions.php : add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' ); function ...
codingteam's user avatar
0 votes
0 answers
59 views

WordPress Custom Page Blog Template Pagination Problem (Pagination Not Displaying)

My website doesn't display pagination no matter what I do or try. Can you help me, please? Tried a lot of different codes and Plugins but no dice. Here is the code for test template: <?php /* ...
gfo95's user avatar
  • 25
0 votes
1 answer
30 views

How call WordPress shortcode inside function file

I am trying to add shortcode to a new WooCommerce tab in the account section that I created in the functions file. add_action( 'woocommerce_account_new-item_endpoint', 'add_new_item_content' ); /** *...
Joey's user avatar
  • 1
0 votes
0 answers
102 views

transition_post_status hook, works - but not if the post is new

I have no idea whats going wrong. My transition_post_status function works if the post is saved as a draft or another status first, then saved again as the 'transferring' custom post status, which it ...
Yasmine Finbow's user avatar
0 votes
1 answer
119 views

Template Redirect Function Only Working When Logged In

I added a template_redirect to my functions.php file, which redirects private staff members to a "Staff No Longer Available" page. However, my code only works when I am logged in. Am I ...
Michelle's user avatar
0 votes
1 answer
77 views

HELP: Code To Check Status And Write Debug Entry

I use a simple function to send out a 'heartbeat' to a website uptime monitoring service (Better Uptime): function my_better_uptime_heartbeat() { wp_remote_get( 'https://betteruptime.com/api/v1/...
David Adams's user avatar
0 votes
1 answer
416 views

Change WooCommerce Order status from frontend form submitted data

I want to have a form on the front end of the site asking for the WooCommerce Order Number and phone number. Once the user submitted the details, it'll check for orders and if the data matched then it'...
Jituu's user avatar
  • 31
1 vote
1 answer
59 views

Filters do not work when there are multiple (one works)

I have this functions code: function my_query($query) { if (is_post_type_archive('mycustomposttype')) { $orderby = sanitize_text_field(get_query_var('orderby')); $orderby2 = ...
Johan's user avatar
  • 309
0 votes
3 answers
375 views

wp_enqueue_script doesn't load JS in plugin

I wrote the following code in a standalone plugin, but it doesn't work Please guide me how to modify the code, so the JS file is loaded. <?php /* Plugin Name: Copy post */ class CopyPostApi{ ...
Fardad Farhang's user avatar
1 vote
0 answers
149 views

Replace block content with an array

I'm using GenerateBlocks and Metabox, and specifically relevant for this post, MB Relationships. I have a query loop created with GenerateBlocks that displays a list of Events (CPT). I have another ...
nomade0's user avatar
  • 27
0 votes
0 answers
20 views

How to use wp_set_object_terms depending on page ID?

The function to set custom term works fine. add_action( 'save_post', 'set_custom_term', 30, 2 ); function set_custom_term( $post_id, $post ) { wp_set_object_terms($post_id, 'guitar', 'instrument',...
Kim Caspe's user avatar
0 votes
1 answer
107 views

Logout redirect via page template without confirmation?

I'm trying to redirect users when they visit my page template template-logout.php, but I keep getting the Wordpress "Do you really want to logout?" question despite wpnonce being generated. ...
Osu's user avatar
  • 1,442
0 votes
2 answers
569 views

How do i set global variable in a function in wordpress functions.php

Please vet this code and help me with how to declare '.($a['link']).' variable such that i can echo its content in single.php function mp3_download_link_att($atts, $content = null) { $default = ...
John Ovye Godwin's user avatar
0 votes
1 answer
169 views

Change Post status based on custom field date +1 day

I have a working script to "expire" a post based on the data of a custom field. The post "expires" (status changes to a custom status archived) on the same day as the ...
nomade0's user avatar
  • 27
0 votes
1 answer
92 views

Remove content links (internal and external), but exclude post at specific categories

add_filter('the_content', 'removelink_content',1); function removelink_content($content = '') { preg_match_all("#<a(.*?)>(.*?)</a>#i",$content, $matches); $num = count($...
unopermanente's user avatar
0 votes
0 answers
268 views

Get all users from role and add to dropdown (select) - wordpress, javascript

I have a shortcode from functions, which retrieves a list of all users from active role. I have managed to get the list into the dropdown list with a little trickery if I wrap a div around the users ...
Masterior's user avatar