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.

6
votes
0answers
160 views

Use author author display name in permalink structure for pages and posts

I need to add the author name as a subdirectory prefix for all user's posts and pages. For example: example.com/johndoe/ //The author page for John Doe example.com/johndoe/category/test-post/ //Test ...
5
votes
0answers
64 views

PHP code in page template vs functions

I've made numerous WordPress sites, and learned PHP practices that I believe to be right, i.e. functions go in functions.php file, nearly everything in functions.php should be wrapped in a function, ...
5
votes
0answers
266 views

static variable loop not working in Wordpress

I have a function in my wordpress theme that deletes the first embedded video in a video post. See code below. This is in the functions.php file. /* - function that hides first video in post content -...
4
votes
0answers
197 views

Customize WordPress Media Manager - Media Window

Im trying to customize the wordpress media manager "add media" window to get it as simple as possible to use. So i want to disable/ hide the following fields/ functions because i dont need some or ...
3
votes
0answers
25 views

Get widget settings function?

I am using this to find if a new widget has been added or removed from my site: serialize(retrieve_widgets()); Works great for added or removed widgets. But it doesn't detect if a widget setting has ...
3
votes
0answers
347 views

Updating users_can_register option?

I have a custom setting page, where i have a radio to Enable or Disable Registration then try to update the wpoption (users_can_register). Screenshot: I've tried both true/false & 1/0 but it ...
3
votes
0answers
860 views

Logging in redirects to correct page but shows logged out content until forced refresh

I'm trying to change some of the content being shown to viewers based on whether they are logged in or not. I'm using the is_user_logged_in() function in my child theme's functions.php to replace the ...
3
votes
0answers
76 views

my function doesn't return my post from today

I'm using gravity form to create some custom post type - as events. Everything is working great, There is some date field to setup the event from x to y date. ALl of this working great. However, I ...
3
votes
0answers
37 views

Date/time limitation of posts where function must be executed

I have this piece of function in my functions.php file: function user_content_replace($content) { $sentences_per_paragraph = 3; // settings $pattern = '~(?<=[.?!…])\s+~'; // some punctuation and ...
3
votes
0answers
120 views

Download external images with function

Actually, i display images on my site from other sites. Url is on a custom field name "couv" I'd like to download theses pictures on my site and create a new custom field with the new value "couv2" I ...
2
votes
0answers
28 views

How to find out what blocks are added by a plugin

I am creating a plugin, which adds a number of blocks defined by JS/PHP as per Gutenberg documentation. I want to display these block names on an admin page. Is there a hook or function I can use ...
2
votes
0answers
183 views

Override woocommerce wc-class function

I'm not good in WP and plugins and will need some help here. I've read that is possible to alter some WC core function with filters and action but probably I didn't understand this correctly. I want ...
2
votes
0answers
85 views

How to change the page break <!--nextpage--> URL from ../post/2 to …/post/page2/

I am referencing the WP codex here: https://codex.wordpress.org/Styling_Page-Links but cannot find a way to customize the post URL for page break ( ) feature. For exmaple: instead of the traditional ....
2
votes
0answers
1k views

Woocommerce add to simple product attribute programmatically

i want to create a function which will add to specific products an attribute programmatically. i use the below code but it doesnt seem to work. $attributedata = Array( 'pa_color'=>Array( ...
2
votes
0answers
1k views

Wordpress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given

I am running Wordpress 4.9.5 and occasionally see the following error in my logs. E_WARNING: trim() expects parameter 1 to be string, array given The stack trace looks like this, so it's not coming ...
2
votes
0answers
329 views

Search user metadata with checkboxes via ajax (almost working)

I have created an ajax search form following some tutorials online, it is working but not exactly how I need it to. Here is where I got the search from. I have US states setup as a user meta field ...
2
votes
0answers
38 views

Trying to inject twitter metadata into <head> using wp_head action in functions.php - get_the_excerpt() returns null

So I followed the "Add Twitter Cards without plugins" this tutorial for how to add twitter metatags into the header using the wp_head method. I have pretty much taken the code as is, and put it in ...
2
votes
0answers
549 views

Function to “Press Update Button” on all posts

tl;dr - I need the equivalent of pressing the "Update" button on many/all posts, without having to manually open each post and press "Update". I'm bulk importing from a CSV into WooCommerce, which is ...
2
votes
0answers
2k views

Move jQuery and Migrate to footer?

I've seen this answer, but I'd like to move Migrate as well. I'm trying to move both jQuery and Migrate to the footer and change the jQuery to the CDN version. Here is the failed code I've tried (Why ...
2
votes
0answers
795 views

bulk change of image setting “link to” to “link to: image url ”

i want every image present on my wordpress site with setting "link to: none" or "link to: post url" became in "link to :image url" ho make this for old post and for new post ? i tried this code in ...
2
votes
0answers
963 views

Overwrite Parent Theme add_image_size in Child Theme

I'm using a child theme of a parent theme. Now on my parent theme, theveloper adds some custom image sizes like this - if ( function_exists( 'add_image_size' ) ) { add_image_size( '...
2
votes
0answers
1k views

jQuery Plugin to use Wordpress functions in AJAX request

I'm using Chained Selects jQuery Plugin to create multiple chained selection fields. I'm using the remote version of the plugin to build the related options by means of AJAX request from a separate ...
1
vote
0answers
16 views

How to make custom posts types display when published for the future

I'm having a hard time accomplishing two things. I've created a custom post type for Events. I would like for the client to be able to post the event by the date. This means publishing posts that are ...
1
vote
0answers
34 views

Make Categories a Dropdown Menu in Media Library

I would like the categories menu to appear as a drop-down in both the list mode and grid mode view of the Wordpress media library. As of now, it only appears as a drop-down in list mode. List Mode - ...
1
vote
0answers
17 views

Move 'current-menu-item' class on #adminmenu li from Posts to Pages for Taxonomy Edit Screen

I've created a custom taxonomy called 'venuecategory' that is hidden by design(not attached to a CPT and does not appear in admin menu). When I'm on this taxonomy's admin page ('wp-admin/edit-tags....
1
vote
0answers
363 views

WooCommerce: How can I get orders with a custom ID in order meta data object?

Because of a project I need help from you. I've searched a lot but I can't find a solution. I'm trying to edit a WooCommerce function named woocommerce_account_orders I've added the field ...
1
vote
0answers
17 views

WordPress Gravatar filter is removing my custom attributes

I am trying to add a style attribute on all the custom gravatar images. However, it is removing the style attribute before final output. Here is the code I am using: $background = ''; $args = [$...
1
vote
0answers
47 views

How to auto refresh when user change postcode

I setup the shipping zones so if the customer is in the local area and enter the correct postcode, "Free local delivery" become active and replace other zones. The problem is the customers is not ...
1
vote
0answers
29 views

trigger html cleanup for all posts

So i know that wordpress will auto clean / format html within posts / pages automatically when switching back and forth from text to visual: https://stackoverflow.com/questions/9907757/wordpress-...
1
vote
0answers
27 views

error custom php function doesn't exists

I was able to successfully set the default page template for a new page, when there is not yet a defined template to be 'member_home_page.php. This works perfectly on my local environment but when I ...
1
vote
0answers
17 views

Facebook Messager Plugin

I deregister Wordpress's default jquery and register the latest jquery. The problem I faced with the Facebook Messenger plugin relied on Wordpress's default to function. Also when I hashed out the ...
1
vote
0answers
416 views

dynamic dependent select dropdown

I have a dynamic dependent select dropdown system that selects vehicle makes and models from a database which works fine but I would like to convert it to use and select parent and child categories ...
1
vote
0answers
10 views

wp-comment author- url +, email filter hook

Don't know how to change '@' and 'HTTP/S' in ALL comment-stuff, so those will be displayed in WP as unclickable contents. Do you have the knowledge and patience to straighten the following lines? ...
1
vote
0answers
179 views

How to use wp_trash_post (or wp_delete_post) for deleting a (or all) post(s) from custom post type?

I know, my question is general and here is some similar questions, I checked the all, but I dont find any solution for my problem... I try using the wp_trash_post() in my function.php, but for some ...
1
vote
0answers
287 views

Show the content that is after the excerpt using child theme

How do I set a value for $stripteaser using the functions.php file in a child theme so that when the_content() is called on post pages only the post exerpt is shown? I have a theme that I am using. ...
1
vote
0answers
38 views

Use third party Library in wordpress

The GA third party library works with php 5.5 and above, i have this. They say to install this via Composer, since i am new to php i have no idea where is it located and will this work on WordPress? ...
1
vote
0answers
197 views

When sale price is 0.00 show only regular price

I run my woocomerce product updates via excel sheet uploads with over 10,000 products. However, with the sale price/promo price column, I have prices of 0.00, 0 and some blank. I want a situation ...
1
vote
0answers
50 views

Custom shortcode outputs plain text instead of HTML at top of post

I am new to wordpress and coding and I need some help. I have a custom post type called 'endorsement' that would like to create a shortcode for that will output a list of posts sorted by a custom ...
1
vote
0answers
33 views

how can i use $_COOKIE[] + PostID to execute the below code?

someone can teach me how to combine $_COOKIE[] + PostID to count one visit by ip + post? I want use this to not use set_transient, my actual code is this: if( !current_user_can('administrator') ) { ...
1
vote
0answers
20 views

create a new page from a custom post type similar to an authors page

I am looking for some direction here as I am unsure where to start. I have a CPT called 'videos' and one of my inputs is a 'artist_bio' text box that creates a box with a biography in it on my page. ...
1
vote
0answers
43 views

Anon function and add_meta_box

I am building a WordPress management plugin (so far going really well) however I am having a slight issue below is what I am trying to acheive and the problem. I am building a Meta manager and for ...
1
vote
0answers
69 views

404 redirect to previous category

Hi I'm looking for code that I can place in my theme's functions.php that will redirect 404 pages to the previously viewed category. For example: If www.example.com/category1/item-name goes to a 404,...
1
vote
0answers
48 views

getting logged in user info (wp-load.php) from parent directory

Directory structure: https://www.example.com/test.php https://www.example.com/blog/wp-load.php test.php: require_once("blog/wp-load.php"); global $current_user; get_currentuserinfo(); print_r($...
1
vote
0answers
316 views

Remove the product category module block from the Woocommerce product page

I want to remove this block: https://imgur.com/a/xzuto this is a category block on the product page overview. I want to remove this block but I cannot seem to work it out. I find a couple of "...
1
vote
0answers
15 views

Function wont fire after custom post type is updated

I have a problem. I cant get this function to fire after a CPT called 'review' is updated on the front of the website. That's fine and the CPT updates with no issues but I need to function to fire ...
1
vote
0answers
142 views

Removing custom meta data

I wrote some code to add some custom meta boxes to my theme admin panel, and it works like a charm. The problem is I can't figure out how to make it so I can remove some of the data too. Example: I ...
1
vote
0answers
25 views

How to allow users to post only in certain category and hide elements from edit page?

I need your help, I am really desperate. In the beginning whenever a user is registered I create category with name based on that user's team name. That user also gets a unique custom role '...
1
vote
0answers
1k views

Fatal error: Call to undefined function cmsms_theme_page_layout_scheme()

I am using a modified version of the Social Activity theme from CMS Masters, and was trying to change the hardcoded versioning of the stylesheet in the header in order to reflect CSS changes I made. ...
1
vote
0answers
111 views

What's the uses of wp_cache_set() or wp_cache_add()?

I see many theme uses wp_cache_set() and wp_cache_add() functions and i can't understand how this function works. How are these functions useful for WordPress developers?
1
vote
0answers
32 views

What did I do wrong in my functions code, that will not change the “Get New Password” text to “Send It”?

I am wanting to change the text "Get New Password" to "Send It" on the lost password page. The following code is what I have in my functions.php file, but it is not changing the default "Get New ...