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
1k views

How to display content If function exist/condition true?

I've created my custom posts. Data from the same is displayed in let's say single-custom-post.php. Now to clean that file and to remove 100 lines of code, I want to make a new file (let's call it ...
0 votes
0 answers
19 views

Let current user know pending posts counts using wp_query

I'm working on a query to let a logged-in user know if the user has more than 5 pending posts. Here's what I ended up with: // Start the query $query = new WP_Query( array( 'post_type' => '...
0 votes
0 answers
13 views

How to remove/hide collapse menu for user/subscriber?

I want to remove/hide the collapse menu item from the dashboard for user/subscriber role only. I don't want to remove it from the admin dashboard. I am the code below to remove it entirely which was ...
0 votes
0 answers
15 views

Uncaught Error : call to product id functions generate [closed]

Error SHOW : Fatal error: Uncaught Error: Call to a member function empty_cart() on null in C:\xampp\htdocs\demo\woocommerce\wp-content\plugins\stenter code hererive-wook-commerce\public\settings\tabs\...
0 votes
2 answers
18 views

Cannot get wpdb data (Error in a simple fuction) [closed]

I'm using Cryto Plugin and want to get coin price data from plugin db. For easy practice, I'm trying to get BTC data. <?php function get_coin_price($coin_symbol) { global $wpdb; $coin_price = ...
0 votes
1 answer
738 views

How to override theme's public static function inside of a trait?

I use a theme which has a public static function to display a part of a page like: trait SomeTrait { public static function some_function() { ?> <div class="some_class">Some ...
1 vote
1 answer
3k views

Pass php dynamic variable to shortcode

I am not sure if there is a simple solution to my problem. The requirement looks simple but unable to find answer even after breaking my head for 6 hours. I have to pass variable from a php function ...
0 votes
1 answer
11 views

How to check post meta isset or not empty during publish/save post?

How to check if a specific post meta isset/!emtpy during updating or publishing a post ( save_post() )?
0 votes
1 answer
1k views

How to sort custom post's category by id from the theme's function.php?

I'm wondering how to sort a custom post's categories in the selection field which I've circled in the screenshot? And I have the following code which generates category listing $args=array( ...
5 votes
3 answers
20k views

How to add first name & last name to default registration form?

is it possible to add first name & last name to the default registration form of wordpress?
0 votes
0 answers
24 views

redirect after submiting post for review

I have a frontend page that allows "Tutor Instructor" role, to create a course and this course is a custom type post called courses, when the Tutor Instructor finishes creating the course he ...
86 votes
6 answers
135k views

What's the difference between home_url() and site_url()

My understanding is that site_url() returns the location where the WordPress core files are. If my blog is hosted at http://example.com/blog then site_url() returns http://example.com/blog But then ...
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 ...
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/...
0 votes
1 answer
24 views

How to inherit field value from parent post into in child / sub post

I have created a custom post type, called 'centres'. This CPT is hierarchical, ie, I can create child pages under each custom post. Centre1 Location1 Contact1 Centre 2 Location2 Contact2 I've ...
1 vote
3 answers
590 views

Keyword checking in Gravity Forms

In Gravity Forms I'd like to include a small keyword checker that is checking the user's message for "spammy" words and stops sending the entry to the admin. For this a hidden field changes it's value....
0 votes
0 answers
13 views

How to avoid saving empty data to sql while using add_meta_box

I'm trying not to save empty data (null) while using add_meta_box function. My code is /** * Register meta boxes. */ function hcf_register_meta_boxes() { add_meta_box( 'hcf-1', __( 'Hello Custom ...
0 votes
0 answers
9 views

Output product category link from WP_Query

I have a WP_Query that outputs products from given Product category name. For each product list I would also like to link to the category of that product, but I'm not sure how. My query: <?php $...
0 votes
0 answers
12 views

How to implement Polylang functions in my theme's php file?

I am translating a site with Polylang that was created by someone else using a custom theme. Some strings couldn't be found by Polylang, so I need to manually register them for Polylang to see. Now, ...
0 votes
0 answers
16 views

How to make WooCommerce payment method field optional?

Here is my current code on a plugin. /** * Field Validation. */ public function payment_process() { if ( 'woo_bkash' !== $_POST['payment_method'] ) { return; ...
0 votes
4 answers
6k views

current_time('timestamp') seems to be different from the real current time

Does current_time('timestamp') have an issue? I am trying to get the current_time('timestamp'), and instead of giving me my current time: Jun 26 2013 14:30 It gives me: Jun 26 2013 21:30 I tried ...
0 votes
1 answer
16 views

How to assign php file(template) to several pages with same prefix page name/slug

Can I assign WP php file (specific template) to several pages with same prefix name/slug using (if is_page(){}) ? If it's possible it could be useful. Is there a php function to do like css selector : ...
0 votes
0 answers
21 views

Unzip file in functions.php, and add it to cron

I have a file in the root folder of my wordpress installation (myfolder, wp-content, wp-config, and all other). I want unzip a test.zip archive in my myfolder folder in root directory. I try this ...
0 votes
1 answer
728 views

Hook into all password resets in Wordpress and get password before hashing?

I'm syncing my Wordpress authentication system with an secondary/external authentication system and my site has at least two ways of resetting the password, including: Password reset email User ...
0 votes
2 answers
623 views

Remove generated category and tag class names from woocommerce product & blog listings markup

I noticed in my wordpress/woocommerce setup that every time i add a tag to a product or a blog post. It adds that tag as a class into the listed item (Product/blog) I also noticed it adds a class in ...
0 votes
0 answers
14 views

How to Display WooCommerce Product Price in WooCommerce Archive

I have created a custom function to display 2 custom fields (ACF) and the price of the product after the item in the WooCommerce Archive/Shop page. My Custom fields are show, but I am unable to get ...
0 votes
1 answer
21 views

Adding onload to body for certain pages

I am looking for a function to add <body onload="prepareFrame('https://airtable embed URL here')"> to certain wordpress pages only. I know how to add a custom body class but not an ...
0 votes
1 answer
1k views

Is it possible to insert text into an html tag using functions.php?

Here's what I mean: I am using a plugin called 'pods' which allows for the creation of Custom (CPT) and for relationships to be formed between those CPT's. However - there's a little flaw that I can ...
0 votes
1 answer
837 views

Help wiht adding fullcalendar.io to a WordPress page

I've been trying to add this calendar to my wordpress page. And I've followed the documentation, but it's still not showing up. This is what I've done. I first added this to my child theme functions ...
0 votes
1 answer
779 views

Set a post expiration and delete a post when expirate

I'm trying to create a function that allows me to delete an article when the date of the day is equal or superior than a date filled in a custom ACF field. I wrote the function below that I placed in ...
0 votes
0 answers
26 views

How to change text color depending on the number value (Using javascript)

I'm trying to change text on the table depending on the meta value I give (number). if meta value >= 7, number text on table changes to green. else if meta value >= 4, number text on table ...
0 votes
2 answers
1k views

Every time I use wp_get_current_user() my plugin breaks

I have been trying to make a sign-out plugin that allows users to sign out from military training activities that they should be at. After they fill out a form explaining why they are not going to be ...
0 votes
1 answer
751 views

Find the method which AJAX GET calls

I need to find bug in a Wordpress site. But I can't find the method (function) that the AJAX GET call runs on backend. That's not admin part of website, but front end part of website. important I ...
2 votes
2 answers
797 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....
0 votes
0 answers
17 views

is_main_query() always returning false

I've built a Wordpress site using Oxygen builder. I'm using the 'Post Types Order' plugin to control the post order. I have an Archive Page for a custom Post Type. For the Loop/Oxygen Repeater I'm ...
0 votes
2 answers
1k views

Set display name from nickname with register process

It is possible set display name from entered string into nickname registration field? I trying do this with simple hook, but after all it is not work. function set_default_display_name( $user_id ) { ...
1 vote
1 answer
1k views

How to install Segment on WordPress without a plugin

I want to add Segment to my WordPress site. I read the best way to do this is to edit functions.php and use wp_enqueue_scripts I've replaced my tracking code with "test" This is the segment code: &...
0 votes
1 answer
654 views

Send mail to author when custom post type is saved

I have a custom post type called "documents". I can add documents (ACF repeater field) there and the users can see them in a frontend-view. Now i need to send an email-notification to the author of ...
1 vote
2 answers
590 views

Unique icons next to each Wordpress menu item

I have Wordpress menus that is seems are put together in the backend somehow. I used wp_nav_menu() to customize the wrap of the menu items slightly. My issue is I have found no direct access to ...
-1 votes
0 answers
14 views

how to limit search to post titles and contents by functions code?

Is there a way to limit search to post titles and contents? I tried below code in the link and its working but its just for titles. I would like to have function code for titles and contents. how to ...
-2 votes
0 answers
12 views

limit search to post titles update the code for WordPress 5.9.3 [closed]

Hi Please update this code for WordPress 5.9.3 many thanks how to limit search to post titles?
0 votes
1 answer
67 views

How to get an attachment id from a filename

I have not been able to find a reliable solution for how to lookup the id for attachments in the media library from a filename as Wordpress does not appear to provide such a function. Most solutions ...
0 votes
0 answers
21 views

Change the behaviour of a button

I'm using Flatesome theme and I have a use case that I need to refresh the page after closing the popup, I'm wondering if I can change the behavior of the close button in Lightbox Popup so instead of ...
0 votes
0 answers
14 views

Disclaimer that will show every refresh of the page

Hello I have here a code that is based on a "where you first access the page you will see the Disclaimer template" but I want it to show every time I refresh the page <?php // ...
0 votes
1 answer
2k views

Show custom default avatar instead of gravatar

I'm using this custom function to get the default avatar from my server instead of gravatar: if(!function_exists('custom_avatar')){ function custom_avatar($avatar_defaults){ $...
0 votes
1 answer
588 views

How to echo a plugin's function into a template?

I've tried checking for a similar question but couldn't find one. If possible please link me to this as I might be creating a duplicate. Anyways.. I am using a basic testimonial plugin (Clean ...
0 votes
1 answer
930 views

Get shortcode attribute value to another function

I am trying to get shortcode attribute value to another function to add inline style.I want to use $color's value to another function. Here is my code <?php /** * */ class MakeShortcode { ...
1 vote
1 answer
233 views

Allow users to create posts without logging in?

I am working on a site where users can share their story. Every story is a blog post. I don't want that they mail me the story and I publish them, I want to provide them a form where they provide the ...
0 votes
0 answers
12 views

Woocommerce Variable Product Dropdown for Custom Shop Template

I'm building out a custom shop template and I'm trying to achieve something like this. Where the user can choose the product variation in the dropdown, choose quantity, and click add to cart without ...
5 votes
3 answers
9k views

Functions.php code that only runs on localhost?

I would like to run an add_action in functions.php only if the theme is being loaded from my localhost development site. How would I get this to run only on localhost? function livereload(){ ?> ...

1
2 3 4 5
112