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
0 answers
4 views

Display ACF category image on archive and single template files

I have written this function to display an Advanced Custom Fields image custom field added to a specific category (News) in WordPress. This image displays on the category archive page and all of the ...
user avatar
1 vote
2 answers
91 views

Wordpress simple 'Hello World' plugin - problems

I am an old-school embedded C programmer but a WP noob, so please bear with me. Here is what I have done so far:- Added a Shortcode in a Theme My function prints out 'Hello World' and is registered ...
user avatar
  • 11
0 votes
0 answers
9 views

Move add to cart above product option [closed]

how to Swop these two fields so that add to cart is above option selector
user avatar
0 votes
0 answers
39 views

Warning: Attempt to read property "term_id" on int - Woocommerce

I would like to create a condition to manually hide product categories within the shop. I already started from a code base but I am trying to understand why if I put the is_product_category() ...
user avatar
  • 21
0 votes
0 answers
11 views

Only some shortcodes aren't working on custom theme

We had the calls setup exact like they should be, but its not showing correctly. We use this function at the bottom of page add_shortcode('test','testing_function') ?> then in the functions.php ...
user avatar
  • 1
0 votes
1 answer
40 views

PHP Notice: Function is_page was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false

In my functions.php I have: // Load Google Optimize script in head function us_homepage_optimize_test() { $site_id = get_current_blog_id(); if(is_page(10) && is_main_site($site_id)) { ...
user avatar
  • 1,626
0 votes
1 answer
52 views

Activate and deactivate two plugins automatically at certain hours

How I can Activate and deactivate two plugins automatically at certain hours? For example, I want the "akismet" plugin to be active only from 10am to 7pm and the other Times (7:01pm to 9:...
user avatar
0 votes
1 answer
18 views

Image loading function not working on archive.php template

I am using the following function to display a post thumbnail or ACF custom field image depending on the page type being viewed. This function is loaded from the inc/template-tags.php file in the ...
user avatar
0 votes
0 answers
23 views

Get URLs for AJAX Filter Checkboxes WordPress

I have a problem with showing and generating URLs for the pre-checked filter. So basically I need links for a specific filter, for example, I'm choosing the Location, the Salary, the Type of Work and ...
user avatar
0 votes
0 answers
12 views

Restrict post to current user in postmeta

i hope someone can help, i'm have not php skill, try with some sample without success. i have a CPT with metafield "email" where stored user email . does its possible to restrict post url ...
user avatar
  • 1
0 votes
1 answer
10 views

change the default order of posts only for specific categories

I want to change the default ordering for posts, to last modified date, but only for certain categories pages (when visiting certain category pages) I have this function code, which is working, but I ...
user avatar
  • 167
0 votes
0 answers
9 views

How to get taxonomy tree ids without running expensive loops

I'm in the middle of building a importer that uses WC API to import products, i've run into an issue where i need to add custom taxonomy tree to the product by ids but i can't figure out how to ...
user avatar
  • 3
0 votes
0 answers
6 views

Set Default Post as Parent Child (Nested) Relation

I want to select post as parent for child posts for default post type not custom post type. By default wordpress allow nested relation only for pages but i want for posts. Anyone have idea how to ...
user avatar
2 votes
2 answers
52 views

iframe not showing in content on blog page

On the post editor field, I have added an iframe code. But on the frontend, it is not showing the content with the iframe code. I have added the below code to print the excerpt on the blog page: <?...
user avatar
  • 31
0 votes
0 answers
11 views

Custom Settings Plugin Save foreach checkboxes

I have these functions that create a form with checkoxes that come with each product attribute(i used a foreach loop) and I'm not sure where it goes wrong here. I want to show all product attributes(...
user avatar
0 votes
1 answer
22 views

send popup after wp_redirect()

Hello Wordpress Developer, I want to ask about how to send popup after wp_redirect(); I'm sending link to user for verify. I just want to let user know that the verify process is done. Here is the ...
user avatar
  • 5
0 votes
1 answer
86 views

How to echo the value of an array element using a function via a shortcode

I want to centralise the prices on our website, so that I can simply update one place, and once updated it propagates to all pages. I don't want to use a plugin. The idea I have is to create an array ...
user avatar
  • 103
0 votes
0 answers
22 views

Remove role of user after X days

I have issues getting this code to work. I want to BUGSexpdate which has a set date to remove a role when the date is reached as I want to "rent" out movies. This code I found on a similar ...
user avatar
0 votes
1 answer
34 views

Message notification for user

I want to create alert system for users. If user get message I want to show info andout it near user image in header. So I create table for message id_message | id_user | sender_name | sender_email | ...
user avatar
0 votes
1 answer
15 views

Add query args if website open in mobile

how do I add a custom query in the URL if my website open in mobile? for example, if open on desktop show: https://example.com I want in mobile URL like https://example.com/?mode=app I want to add &...
user avatar
0 votes
1 answer
24 views

Execute PHP code only with specific user role

I have a WordPress website with woocommerce and I want to set a minimum order quantity for products. I have found code online which does exactly what I need it to do and it works perfectly.(the code ...
user avatar
0 votes
0 answers
17 views

How can i call a functions.php function, from inside my plugin class?

I have a function get_finance() inside my functions.php file. It is used site wide and I don't want to move it. In my plugin, I can call all the other functions inside my class or other included ...
user avatar
0 votes
1 answer
23 views

Get slug of current category in functions.php

I want to use a certain archive template for a bunch of different parent categories. Therefor I try to change the archive template by using the 'archive_template' filter in functions.php by ...
user avatar
0 votes
0 answers
14 views

Change Language Title Pagination on Subdomain non Multisite

Please Help Me, Iam use WordPress non Multisite, but my website use multiple subdomain from category. All Subdomain use Language Default "Bahasa Indonesia", but i want change only title ...
user avatar
0 votes
0 answers
7 views

Make all scripts and styles be placed in <head> [duplicate]

I have approximately 25 scripts and styles, and wanted to know if it's possible to make a function that hooks into the wp_register_scripts and then apply the $in_footer to false on all assets. So far ...
user avatar
  • 101
0 votes
0 answers
21 views

Build a must-use plugin that tracks when other plugins are activated or deactivated

Here I am trying to utilize add_action to add a callback function to the hooked action of 'deactivate_plugin', but my function is not echoing as I expect. $plugin = 'polls_plugin';<br> function ...
user avatar
  • 1
1 vote
1 answer
54 views

WordPress notification if new post published

I use WordPress and I want to alert users if new post with post_type = job_post was published. Also I want to show amount of new post. So I add to function.php global $new_job_count = 0; function ...
user avatar
0 votes
0 answers
27 views

wordpress built-in Jalali date convertor

I'm developing a new plugin for a client and he wants dates to be in Jalali. As I changed language of WordPress to Persian, the posts date automatically changed to Jalali. So I Think maybe WordPress ...
user avatar
  • 101
0 votes
1 answer
30 views

Disable autosave with `function.php` for custom post wordpress?

I need disable auto save with function.php in wordpress. What should I do? Thanks
user avatar
0 votes
0 answers
11 views

sort metabox columns in listing Single

Hello WordPress community! I modified an existing meta box which is page_attributes. I grafted it to the articles and it allows me to give an order to the posts. I want to add the column to the ...
user avatar
0 votes
0 answers
19 views

remove specificly the last <p> tag in all posts

How to remove the last line of content in all of my WordPress posts, which always have its own tag <p>...</p>? Ex: <p>content I want to keep</p> <p>line I want ...
user avatar
0 votes
1 answer
26 views

User filter posts by year

I am looking to add a filter to a page so users can select the year and view only posts from that year. Something similar to the filter on this page: https://www.economist.com/weeklyedition/archive A ...
user avatar
  • 101
0 votes
0 answers
11 views

How to Redirect Buddypress Directories To Login Page For Non Logged in Users

How to Redirect Buddypress Directories To Login Page For Non Logged in Users? I'm also using the Yuzify plugin. It gives a code for it, but it's not working on multisite. Can anyone modify this code ...
user avatar
0 votes
0 answers
11 views

How to set value selected using select2 jquery plugin

In my file, i have small html bellow: <div class="dropdown-mul-2"> <select style="display:none;" name="dom767_options[all_posts][]" id="mul-2" ...
user avatar
0 votes
0 answers
11 views

bp-custom.php is not working on a WordPress multisite environment. how to fix it?

I'm using the youzify plugin. It has an option: if you want to add a custom code, you need to create a file named bp-custom.php in the WordPress plugin root folder. And youzify provides some code on ...
user avatar
1 vote
0 answers
23 views

How to combine wordpress_logged_in cookies in one cookie?

I'm trying to optimize my server to consume less resources as possible and increase overall performance. In my site I don't see a need to recompute same requests for users or guests every time. The ...
user avatar
  • 111
0 votes
1 answer
49 views

WordPress login set cookie that survive browser exit (wp_signon function)

I've read all the relevant question here on StackExchange and I haven't found a solution. Here's the problem: I use a plugin to use Google OAUTH to login in Wordpress. All working correctly, but I can'...
user avatar
0 votes
1 answer
21 views

How to stop media_sideload_image from running when deleting a post?

I have a code that downloads an image and saves it to the media library when you save a post that uses a certain block. The code runs perfect but downloads the image again if you delete the post. How ...
user avatar
0 votes
1 answer
29 views

Reset postdata not working on WP_Query in functions.php

I'm running a WP_Query in my functions.php, so I can easily access some ACF-fields in my code without having to run that query on every page. However, the loop changes the post ID to the CPT I'm ...
user avatar
  • 289
0 votes
2 answers
24 views

Filter nav menu items HTML tags and wrap inner text with span

I am using the following filter to select <a> tags from a specific menu that have no attributes (href, class, etc.) and replace them with <button> tags. add_filter( 'wp_nav_menu_items', '...
user avatar
0 votes
0 answers
12 views

Woocommerce order status payment

I have some issue with Woocommerce client already do the payment, but then i see as order pending payment, but this should be in order status processing thats the default settings
user avatar
0 votes
0 answers
21 views

Customise Grouped Product display in Woocommerce with custom column

I am trying to display the grouped product where i need to display REF and SKU/Part Number in the table as shown in the screenshot from another website i have seen. By default it only shows the ...
user avatar
0 votes
0 answers
24 views

WP Container Displaying Only on First Page of Archive

I have the following code for a two-column container: <div class="rh_content rh_content_above_footer rh_page__content"> <div class="wp-container-3 wp-block-...
user avatar
0 votes
1 answer
24 views

I want to display latest post in marquee [closed]

<?php /* Plugin Name: Breaking News */ function rif_breaking_news(){ ?> <div class="breaking_news_box" style="background: none repeat scroll 0 0 #2E8B57;...
user avatar
0 votes
0 answers
48 views

wp_nav_menu displaying all pages

As the title says, I'm using wp_nav_menu in header.php to load in the audience, secondary, and main menus and when I do, every menu contains every page - or at least many more pages than I selected ...
user avatar
  • 1
0 votes
1 answer
30 views

WordPress 6.0 upgrade caused my custom function to stop working

Not working on WordPress 6.0: https://thealliance.health/for-providers/resources/provider-news-archives/ Working dev site on WordPress 5.9.3: https://ccahdev.wpengine.com/for-providers/resources/...
user avatar
  • 1
0 votes
1 answer
38 views

Add php code to wp_print_scripts?

Is there a way to add inline php code to the editor using wp_print_scripts? I'm trying to find a way to display text from a php string into a value of input of a block. Here's my code: function ...
user avatar
0 votes
0 answers
23 views

Getting text from custom field from customizer

So I've created a panel in the customizer section in WordPress to add the phone number to the site. It works fine in the back end but it wont show up in the front end here is my functions.php ...
user avatar
  • 5
0 votes
0 answers
39 views

Dynamic URL Rewrite for Custom

I have a custom post type called Hotels which I woud like to link to using the below url structure: /{country}/{state}/{hotel-name} I am fetching and inserting posts dynamically, so I do not know the ...
user avatar
1 vote
0 answers
20 views

How to change or add user role after getting post request data about pay? [closed]

How to change or add user role after getting post request data about pay? qiwi2.php file in theme folder: <?php include($_SERVER['DOCUMENT_ROOT'].'/wp-load.php'); $qiwi = [ "public_key&...
user avatar

1
2 3 4 5
112