Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
20 views

Access WP files on “server 1”, from “server 2” - using wp-load on an external website

My setup consists of a "members area" which is set aside from my Wordpress install. This members area is written in PHP. Until now, ive been using the following code in a PHP file to pull in the WP ...
0
votes
1answer
15 views

load CSS only for administrators on backend

I am trying to load a custom styles sheet but only for administrators My code works fine by itself: function admin_style() { wp_enqueue_style('admin-styles', get_template_directory_uri().'/admin....
0
votes
0answers
11 views

sql query page listing with option selected

I want to separate a page page from the sql query. for example current page and last page with option selected. my listing page code <ul class="list-group"> <h2 class="h3">...
0
votes
2answers
32 views

How can I automatically delete comments that contain a URL?

My WordPress website is being bombarded by spam comments. Nearly all of them contain a valid URL. How can I delete these comments automatically? I don't want to put them into the review queue; I just ...
0
votes
0answers
17 views

Run function for specific user only

I've created following function to run a stylesheet for the admin area, but I want to runt it only for 'shop_manager' this user role and for others, it should not make any modifications from that ...
0
votes
0answers
11 views

Require_once failed to open stream WordPress

I've been trying to create a small plugin to do some basic tasks on my website. I created the plugin which was initially working fine, I made no changes and for some reason it no longer works. Here ...
0
votes
0answers
11 views

using global variables and performance

I use global variables to retrieve all sort of available data, especially $post and $posts, for example in order to retrieve the url of a user from the post loop instead of using ...
1
vote
2answers
84 views

Wrap gutenberg block ‘div’ in other elements/extra HTML

I’m trying to add HTML wrappers around a block to create a clipping effect, something like the below code. It has been suggested this might be possible with the block save or block edit functions? I ...
1
vote
2answers
36 views

Running CRON on Server with WP Function

How can I run a WP function on server cron? Background: I can't run it on wp_cron because the website is not published and will not be, so there will be no visitors. Tested cron job without wp ...
0
votes
0answers
26 views

How to check if a user is logged into WordPress via perl-based download script?

I'm trying to implement code into a perl-based download script in order to check if a visitor to a download url has logged into WordPress. Otherwise do not allow the download. The direct download ...
0
votes
1answer
27 views

Pagination 404 error(I have refreshed the permalinks and tried several previous options)

I am using pagination in wordpress, the truth is that I have used it several times. But this time, when I access page number 2, I get an error 404. I've searched a bit and I've tried several functions,...
0
votes
0answers
21 views

Change custom rewrite rule when permalink is updated/changed

I have a scenario where i need to make a rewrite rule dynamic so that when permalink is changed the re-write rule should get updated as well function rewrite_rule() { global $wp_rewrite; $...
0
votes
1answer
16 views

Redirect website domain (including all pages) to external URL after Popup message (few seconds)

I am new to wordpress and I have made custom code as below. Where I can place this custom code in wordpress. I want to redirect the website domain and all pages but wanted to display popup message for ...
0
votes
1answer
25 views

AJAX error handling for submit function in functions file

I have created a custom function in my functions.php to handle form submissions for a Mailchimp subscriber list. I am making an AJAX call in my JavaScript to process the PHP. The problem I am facing ...
1
vote
2answers
35 views

Add dynamic links in WordPress custom theme

I want to implement a system to insert custom links in my wordpress custom theme. I don't want to hardcode these links inside my theme. These links are for the socials or partners website. So they ...
0
votes
0answers
15 views

How to display report of users using Gravity Forms?

I am using WordPress and the Gravity Forms plugin. I am trying to print/run a report of users based on meta key, meta value and role selections, using a simple Gravity Form to choose those selections. ...
0
votes
1answer
22 views

Possible to merge these two functions?

I have these two functions. The difference is that one is filtering custom taxonomy (is_tax) and the other is filtering generic WordPress tags (is_tag). The work as I'd like them to be it seems that ...
-1
votes
1answer
21 views

WP_Query and DES sort for Custom Taxonomy based upon a meta field?

Is it possible to filter events (WP Query) within a Custom Taxonomy archive by ‘Start Dates’? I create a Custom Post Type called “Events” and in that “Events” is a Start Date When I view Custom ...
-1
votes
1answer
26 views

Masking external links with internal link for member-only

I'd like to know how I should implement this code, to filter URLs for members and non-members? Should I put the code into the functions.php file? $user = wp_get_current_user(); if( $user->exists ) ...
0
votes
1answer
22 views

Shortcode for Listing Users from Meta Value?

Trying to display a list of users that match certain criteria using a shortcode with parameters. Here is what I have so far, but for some reason it does not display anything. I am pretty new at this ...
0
votes
1answer
20 views

Pass post ID from archive template to functions file

I have an archive template where I am displaying a "featured post" at the top of the page. I am building my post loop for the rest of the page in the functions.php file. What I would like to do is get ...
1
vote
1answer
31 views

get author_name from queried post

All I'm trying to do is, get the author name of the current post and set it's name as a tag. I tried changing author_id to author_name but didn't really get anything back. wp_set_post_tags should ...
0
votes
2answers
79 views

use loop to return blog details

I want to return information about a blog. It could be, author name, title, date, country whatever just to test. <?php $post_id = get_the_ID(); while ($post_id != 0) { ...
-2
votes
2answers
60 views

how to loop through blog posts in php

I need help looping through a simple php code. What I'm trying to achieve is the following: Start Loop Look for all the posts Add the author first & last name as a tag (links to /tag/firstName-...
2
votes
1answer
27 views

How can I default to all WordPress roles when parameter is not included in shortcode?

I am trying to set up a generic shortcode in WordPress with parameters for user meta key, meta value and roles that will count the total number of profiles that include certain values. So far I have ...
0
votes
0answers
46 views

How Can I Display the Last Modified Date for User Profiles on WordPress?

I'm trying to add a "last modified" date to user profiles on WordPress. I'm using the Ultimate Member plugin, so I would prefer to to find a way to save this date to a meta-key that I can pull when I ...
-1
votes
1answer
48 views

show limited tags in an article

I have a code that returns all the tags for the article. But that is not what I want, I only want to return the author name as the tag. <?php the_tags() ?></span> <br /> This will ...
0
votes
1answer
26 views

Two 'If Statements' is my syntax correct (functions.php) and what is 'false'

The following code works great. I would just like to know if it is correct to have two 'If' Statements like I have done? (The purpose of this snippet is to replace the generic "Category, Tag" and ...
2
votes
1answer
60 views

What is the criteria for pluggable functions?

Why are certain functions pluggable (overrideable) in WordPress core and others not? (I note on the Codex page regarding Pluggable Functions no more are to be added in favour of filter usage.) But ...
0
votes
0answers
39 views

Remove and replace the “Category: from the_archive_title with custom text

My question has been partially answered here but what I am trying to do is replace the 'Category: Word' in the page title with other text. So, my question, unlike the one asked previously, is - how ...
0
votes
1answer
20 views

Replace theme function

I am a PHP developer but I am new to WordPress so there may be simple things I don't know how to do. I made a change on a theme file to change the behavior of the theme. Only changed 6 words and ...
0
votes
1answer
25 views

WordPress redirect JavaScript and CSS using function.php/child theme

Is it possible to redirect JavaScript and CSS calls using something function.php for example? I used WP Hide & Security to rename some of my plugins and it has functioned well but it clashes with ...
0
votes
0answers
13 views

Competing Login Redirects - Need to be Combined?

I currently have two login redirects in my general-functions.php file in my mu-plugins directory for my multisite installation. The first one is for someone who logs in from a specific page. That ...
0
votes
0answers
21 views

Erase ALL CSS and javascript Type tag

i need erase all type tag for styles and javascripts for my wordpress. I have this code and this work, but not 100%: //* Remove type tag from script and style add_filter('style_loader_tag', '...
0
votes
1answer
18 views

Add code to Functions.php

I want to know if I add some short code in functions.php in my theme and solve my problem, What will happen if I update my Theme ?? is my short code delete after update ?? will i have any problem with ...
0
votes
3answers
45 views

Error call_user_func_array() expects parameter 1 to be a valid callback when using image_size_names_choose

I'm using the example from add_image_size() | WordPress Developer Resources to try to add custom image sizes to the admin media selector. add_filter( 'image_size_names_choose', 'my_custom_sizes' ); ...
0
votes
1answer
21 views

Shortcode from a function not working

I am trying to create a shortcode from a custom function in WP but it seems like I'm doing something wrong. I have a function in child's theme function.php and add_shortcode code: function ...
0
votes
1answer
42 views

Return newly created category by code

How would I return a category that I've just created. I need it to be under the current blog. <?php $category = get_term_by('$first_name', '$value', 'category') ?> the above ...
0
votes
0answers
40 views

How to access custom class methods from any include without using global

I am trying to do the following functions.php class Test { public function hello(){ return 'Hello'; } } $test = new Test(); header.php or any other include echo $test->hello();...
0
votes
1answer
34 views

Unzip_file causing Media file upload error

When I attempt to use the unzip_file function below in my functions.php: require_once(ABSPATH . 'wp-admin/includes/file.php'); WP_Filesystem(); $destination = wp_upload_dir(); $destination_path = $...
0
votes
1answer
11 views

(Divi): How to make Wordpress load images of specific size for Blurb modules on given page with a funciton?

I have 28 pictures uploaded to media library, each around 3mb. Wordpress has already created resized copies of those: thumbnails, medium and large. The pictures are used as Divi's Blurb module images ...
0
votes
3answers
82 views

Cannot call function from Functions.php in template

I have a custom php file in wp-content/themes/xxxx/modules/custom.php and i want to call function from Functions.php. Right now all my functions (same function) everywhere in different files, because ...
0
votes
2answers
33 views

category not display in word press grammatically

I'm trying to create a new category in the taxonomy.php called 'USSERS'. I have followed few examples online and got till this part. function insert_term( $name,$tax,$parent='' ,$slug='') { $...
0
votes
0answers
18 views

add users to newly created category in single.php file

I need your help with this problem. I have asked this on SO but haven't gotten anything so please don't remove this for that reason. I have a WordPress site and all of it's files/database. The site ...
0
votes
1answer
29 views

Postback redirect through add_action is not triggered

template: <form action="<?php echo esc_url( admin_url('admin-post.php')); ?>" method="post"> <input type="text" name="boo" id="boo" required> <input type="hidden" name="...
2
votes
0answers
37 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="...
0
votes
1answer
25 views

Warning and fatal error

I am getting this error when running my website : Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'sanitize_comment_cookies' not found or invalid function name in ...
1
vote
1answer
33 views

Changing Woocommerce flat rate every nth number of items

I found a semi-functional solution for my problem in this answer WooCommerce - Flat rate shipping based on X quantity steps? But this counts the total qty of the cart items which it doesn't quite work ...
0
votes
1answer
24 views

Appending „read more” to the excerpt conditionally

I wonder if anyone knows how to add an if to this function. I need the read more to only be added to the the_excerpt when the category is 429 function mywiki_trim_excerpt($mywiki_text) { $text = ...
0
votes
1answer
39 views

How to display the_archive_title() and the_archive_description() - “weird” interaction

I've got the following code in my "pagetitle" template partial: <?php the_archive_title( '<h1>', '</h1>' ); the_archive_description( '<span class="archive-description">', '</...