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
51 views

comment_post (if comment is approved OR $comment_approved === 1) not working?

I am working on a code through which I can send emails to the user when his/her comments get approved. then I get to know about comment_post. but it is not working. comment_post is working for the ...
user avatar
0 votes
0 answers
31 views

Wordpress functions.php conditional include another functions file

In my wordpress functions.php I have calls to include other function files. For example like so: include("functions/articles.php"); include("functions/custompost.php"); Within ...
user avatar
1 vote
0 answers
33 views

How add various functions within 1 conditional?

I want to add some gravity forms filters in my functions.php. I have the code up and running, but I would like to improve this snippet with a condition. As I only need these filters on 1 page of my ...
user avatar
0 votes
2 answers
363 views

How a HTML form can trigger a PHP function?

I'm new to the Wordpress/PHP world. I want my page be able to communicate with an API that I build myself. So for this I have a form on my Wordpress Page using a HTML code widget which looks like this:...
user avatar
0 votes
0 answers
14 views

update custom taxonomy custom fields

I have a function that runs when when i click save on custom post type posts. It gets some values from the post and i want to update the custom field of the post's custom taxonomy add_action( '...
user avatar
0 votes
2 answers
71 views

require_once() if a product in woocommerce contains a tag [closed]

I try to require_once() a file, if the condition of a specific tag is met, on a woocommerce single product page. I've added following to my functions.php if(has_term('xyz', 'product_tag')){ ...
user avatar
0 votes
1 answer
37 views

How exclude or skip post type with get_next_post_link

I have a post type called families where I add personal information of each family, inside the data there is an option called status. *IMPORTANT: The fields are created with ACF CUSTOM FIELDS These ...
user avatar
  • 1
0 votes
0 answers
26 views

Members only function, but allow account activation [solved]

I have small multisite and one of site is restricted. When you go site you will see login page first because this function: function members_only() { global $pagenow; // Check to see if user ...
user avatar
  • 3
0 votes
1 answer
84 views

Possible to hook into Media Library preview File column and use a custom image?

The project I'm working on, I couldn't find an easy way to have WordPress create the thumbnails sizes I needed without tons of waste, nor to simultaneously generate WebP versions, so I disabled the ...
user avatar
1 vote
2 answers
42 views

Automatically assign video 'poster' value to 'filename' for archive listing

One of my sites is used as a personal diary with >5000 videos uploaded within the media library. Each post uses the following shortcode, disabling pre-load and assigning a manual poster. This ...
user avatar
1 vote
1 answer
121 views

wp_get_attachment_image function size argument not working if I also add a custom class

I'm trying to output some images the right way, using the wp_get_attachment_image function. Here's how I do it: echo wp_get_attachment_image( $image_id, 'image-size', '', [ 'class' => 'some-class' )...
user avatar
  • 13
0 votes
1 answer
37 views

How do I modify the custom footer text and get theme version number to show in wordpress admin?

I am trying to modify the footer text inside the wordpress admin and also get my custom themes version number to show as well but my function is not working properly, I am still very green at PHP ~ ...
user avatar
  • 105
0 votes
0 answers
22 views

Dropdown category field inside repeatable metabox

I'm building a repeatable metabox with different fields in the Page editor: Name, Email, Tag, Categories. To display the dropdown category field inside the metabox I use wp_dropdown_categories(); The ...
user avatar
0 votes
0 answers
40 views

Run function with schedule is not working correctly

i´m trying to run a function with a schedule but the response is empty. I am developing a plugin where i will send a json encoded array to my IoT service. The service is fine. All other functions are ...
user avatar
0 votes
0 answers
27 views

How to change basename url for wp-admin?

I want to apply some conditions based on site url, e.g redirect login.php, default files etc If a uri is /wp-login.php we do use basename as written below $custom = basename($_SERVER['REQUEST_URI']); ...
user avatar
  • 39
1 vote
0 answers
256 views

ACF: how do I get the fields and its values of a specific group?

<?php $fields = acf_get_fields('6066'); ?> <?php if( $fields ) { foreach( $fields as $field) { $value = get_field( $field['name'] ); if ($value) { echo '<...
user avatar
  • 287
0 votes
0 answers
25 views

Create shortcode for metabox gallery

I have a metabox gallery in a custom post type. Usually I display the gallery in the front end using the following PHP code in my theme: $gallery_images_1 = get_post_meta( $post->ID, '_post-metabox-...
user avatar
0 votes
2 answers
146 views

Allow a user or role to view drafts and previews, but not other admin privileges?

How do I allow a specific user or a specific role to view drafts and previews, but not allow them to edit posts or have any other admin capabilities? I can add a custom capability to a role, but don't ...
user avatar
  • 279
0 votes
0 answers
63 views

Retrieve alt text by referencing the img src

I have a website with 400+ images. Using a spreadsheet plugin I've been through and manually added alt text to each of the images. The problem I have is that the pages are built with a page builder ...
user avatar
0 votes
1 answer
16 views

Attempting to list all product categories and the price range of all products within them

I'm trying to display a list of all product categories and the price range of the products within those categories. E.g Headwear – £30-£150 Shoes – £35-£300 Where "Headwear" is the Product ...
user avatar
0 votes
0 answers
19 views

get category in list of posts // shortcode for custom related posts

i am looking for a solution to get the category of the related post. I created a shortcode (@buttered_toast helped me, thanks for that) that can be inserted in a post. This shows custom IDs/posts. It ...
user avatar
  • 3
1 vote
0 answers
82 views

How to store data from multiple forms using ajax and php

I have custom post loop, and for each product I have form. I'd like to store data in array for each click submit button in each product. E.x. Product A with Form and some values (price,quantity) click ...
user avatar
  • 13
0 votes
1 answer
39 views

shortcode // get posts by ids

I am looking for a solution to display custom posts in a shortcode. For one post this already works as desired, however I would like to specify multiple IDs. like: [posts id=1, 2, 3,4] Cause I come ...
user avatar
  • 3
0 votes
2 answers
36 views

How to require a config file in a template and in function.php?

I made a config.php file where I store some arrays for configuration like LDAP and other things. I need to call it on different templates but I also need to require it into function.php. When I do ...
user avatar
1 vote
1 answer
75 views

Can I write 'RewriteCond' using 'functions.php'?

I want to add 'rewrite condition' in .htcaccess but unfortunately I don't have access of that. Can I write conditions in functions.php ? If yes, how to achieve that ? I want to add these lines: ...
user avatar
  • 39
2 votes
3 answers
612 views

Enqueue script o style only if a template part is loaded

I have registered some styles and scripts that should be loaded if a template part is loaded in a template file. For ex: in home.php <?php get_template_part( 'template-parts/external_links'); ?> ...
user avatar
0 votes
1 answer
27 views

Custom meta box values are not getting saved for my custom post type

I have created one dummy post type to check the values, if it's getting saved or not. However it's saving values for 'text input and text area' but remaining values (checkbox, select, images) are not ...
user avatar
  • 39
0 votes
0 answers
21 views

How to exclude meta no index pages from wp_list_pages

Can I exclude pages that use a meta no index or are no indexed from a plugin like Rank Math from wp_list_pages args?
user avatar
  • 1
0 votes
0 answers
26 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 ...
user avatar
0 votes
2 answers
70 views

the_date() and the_time() functions display actual date an time instead of published date and time

It's really hilarious but my the_date() and the_time() functions show the current date and time instead of the post's publication time, therefore at each refresh of the page, the time changes ...
user avatar
  • 13
0 votes
1 answer
70 views

How to obtain the recent posts without their content in an efficient way?

It would be great to make a single DB request but I don't know how to do that either. I have this code and it works but I want to change it to be more efficient: $cs = get_categories(array( '...
user avatar
0 votes
0 answers
31 views

Cannot find the php_ini configuration file to find my error log to see why my code is not working

would anybody know where I could find the php_ini configuration file to look for error log, as my code will not work in wordpress. I went to app folder, then public folder, but only see wp_config.php ...
user avatar
1 vote
1 answer
109 views

Disable auto-resizing of uploaded images, but only for certain filename

How can I totally disable the wordpress auto-resizing when uploading images, but only for images that have a certain string in its filename. Eg. disable auto-resizing on images in which its filenames ...
user avatar
1 vote
1 answer
234 views

get_current_screen() return null

I want to put JavaScript code on certain pages in frontend. But the output return null . add_action( 'wp_footer', function () { $screen = get_current_screen(); var_dump( $screen ); }, 999 );
user avatar
  • 25
0 votes
1 answer
164 views

Noscript not working as it should in wordpress site

This is what I've done in my custom functions mu-plugin: function jsdisabled() { print '<noscript> <div style="margin:auto; display:table; text-align:center"> <div style=&...
user avatar
0 votes
1 answer
18 views

remove edit link only for published post and pending post

Currently i m using this shorocdes add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 ); function remove_row_actions( $actions ) { if( get_post_type() === 'post' ) unset( $actions['edit']...
user avatar
0 votes
1 answer
58 views

Adding HTML Code to Replace Text in PHP

I want to change my download button for non logged in users. Instead of the download button I want to show a custom HTML code with message to login/register. The below code is hiding the button but ...
user avatar
0 votes
0 answers
22 views

Allow a particular user to access a particular plugin?

Hi I am using a Tutor LMS website, so I wanted to give access to the tutor instructor(user) to access a single plugin Presto player in his dashboard. I tried many plugins to change the capabilities ...
user avatar
0 votes
1 answer
62 views

Extending a custom framework built into WordPress to automatically turn the 'Search Engine Visibility' setting ON / OFF, dependant on environment

I have a WordPress framework that I am currently working in, it is a thing of beauty, however it is not what I am used to. I am attempting to extend this framework to automatically turn the toggle (...
user avatar
0 votes
0 answers
44 views

How to Send Pingbacks for all Posts in WordPress?

I deleted all my pingbacks and wanted to generate them again. I found a some code on WordPress's site, which showed the function pingback($Content, $ID) It send pings to all links mentioned in content....
user avatar
0 votes
0 answers
592 views

Reliable way to add nonce to HTTP Header in WordPress?

I am trying to implement CSP on my wordpress site. Inspired by this question, https://stackoverflow.com/questions/50002041/adding-nonce-to-script-tag I tried to build a way to add nonces to my ...
user avatar
0 votes
1 answer
38 views

Why does the post_type_link hook everything twice?

I've added a Wordpress hook: add_filter('post_type_link', 'custom_post_type_link_venue', 11, 3); Everything in that hook prints twice. I've simplified it to its minimum. function ...
user avatar
  • 125
0 votes
0 answers
19 views

Products listing check if meta checkbox is checked

I've created ajax filter for products categories and classic archive product page where is listed all products. I've created Is new product option checkbox for products. But I have problem that every ...
user avatar
  • 1
0 votes
0 answers
13 views

How to add extra value to permalink

We want to add the venue slug to the URL of the product. My current product URL looks like this: http://antwerp.test/en/offers/guided-tours/history/guided-group-walk-through-the-ruien/ Each product ...
user avatar
  • 125
0 votes
0 answers
24 views

Title and URL Error in Breadcrumb Navigation for Custom Post Types

I have this code I got from here on StackOverflow. It works great across my wordpress site but the problem is that on the custom post type single pages, the parent category's link it fetches for every ...
user avatar
0 votes
0 answers
15 views

Show all people who commented on all posts by an author

I need to make a feed, showing everyone, or at least the last ones who commented on an author's posts. I've tried it in different ways and I haven't been able to. Can you do it? example: Juliana ...
user avatar
0 votes
1 answer
39 views

Adding a tag_ID column into Categories inside the admin dashboard?

So right now there are four columns when you navigate to Posts > Categories (or your custom Taxonomy): Name | Description | Slug | Count I'm working with taxonomy term_id a lot, so I need to see ...
user avatar
  • 203
0 votes
0 answers
19 views

Trying to update Woocommerce meta values

I'm using WP User Frontend Pro and WooCommerce on my site. Created custom add product form to my site and it almost works perfectly. All my products should virtual and checked my DB, its meta key name ...
user avatar
1 vote
1 answer
42 views

Display post lists in 2nd paragraph

Hello great WordPress developers, I would like to list posts from a specif category in the 2nd or middle paragraph of the post. I tried adding some scripts to my function.php to achieve that, but I ...
user avatar
  • 13
2 votes
2 answers
123 views

Disable External Pingacks on WordPress Posts and Only Allow 'Self Pings'

I use wordpress for my Social Media site. WordPress Pings allow other blog posts to appear in comments when they link to us. I want to limit it to only blog posts created on my own site. Basically I ...
user avatar

1
3 4
5
6 7
112