Invoke action on a “post” in functions.php?

I have a button in admin that invokes a URL (GET) like this:


It creates an invoice when pressed.

I have access to all variable values in this URL, so I can recreate it. I also have a function in functions.php that gets invoked when an order is paid and complete.

My question is, how can I invoke that URL (or the internal wordpress action) inside my function in functions.php?

Sorry if it’s a basic question. My googling skills failed me.

Last updated posts shortcode in functions.php

I’m searching to create a shortcode inside function.php child theme, to show last updated posts with thumbnail.
I have this code that works into page template:

    <ol class="list-numbered">
    // Show recently modified posts
    $recently_updated_posts = new WP_Query( array(
        'post_type'      => 'post',
        'posts_per_page' => '13',
        'orderby'        => 'modified',
        'no_found_rows'  => 'true' // speed up query when we don't need pagination
    ) );
    if ( $recently_updated_posts->have_posts() ) :
        while( $recently_updated_posts->have_posts() ) : $recently_updated_posts->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?>
$size = 'thumbnail'; 
 $attachments = get_children( array(
        'post_parent' => get_the_ID(),
        'post_status' => 'inherit',
        'post_type' => 'attachment',
        'post_mime_type' => 'image',
        'order' => 'ASC',
        'orderby' => 'menu_order ID',
        'numberposts' => 1)
    foreach ( $attachments as $thumb_id => $attachment ) {
        echo wp_get_attachment_image($thumb_id, $size);
        <?php endwhile; ?>
        <?php wp_reset_postdata(); ?>
    <?php endif; ?>

But I would insert into functions.php file and call the shortcode.
Do you have some ideas?
Thanks in advance.

How to change a wordress plugin php code in my child’s functions.php file?

I’m trying to edit EmailOctopus plugin, this is part of their “form.php” code:

        <p class="emailoctopus-success-message"></p>
        <p class="emailoctopus-error-message"></p>
        <div class="emailoctopus-form-copy-wrapper">
            <input type="hidden" name="emailoctopus_form_id" value="<?php echo absint($form_id); ?>" />
            <input type="hidden" name="emailoctopus_list_id" value="<?php echo esc_attr($list_id); ?>" />
            foreach ($custom_fields as $custom_field) {
                echo '<div class="emailoctopus-form-row">';
                echo sprintf(
                    '<label><span class="emailoctopus-label">%s %s</span><br /><input type="%s" name="%s" class="emailoctopus-custom-fields" tabindex="%d" /></label>',
                    $custom_field('tag') === 'EmailAddress' ? '<span class="required">*</span>' : '',
                echo '</div>';
                $tabindex += 1;

Only thing I want do to is edit this HTML and add a placeholder=”something” here:

'<label><span class="emailoctopus-label">%s %s</span><br /><input type="%s" name="%s" class="emailoctopus-custom-fields" tabindex="%d" /></label>',

I could do this manually but I don’t want to edit the plugin directly but rather I want to do it in functions.php of my child WordPress theme, how can I do that there?

Custom Post Types – How does this CPT code add a hidden "Products" category in functions.php?

Here is the code I changed from

* Creating a function to create our CPT
* just drop this in functions.php inside your theme file basically...
* You replaced all 'twentytwenty' with 'twentyseventeen'

function custom_post_type() {

// Set UI labels for Custom Post Type
    $labels = array(
        'name'                => _x( 'Products', 'Post Type General Name', 'twentyseventeen' ),
        'singular_name'       => _x( 'Product', 'Post Type Singular Name', 'twentyseventeen' ),
        'menu_name'           => __( 'Products', 'twentyseventeen' ),
        'parent_item_colon'   => __( 'Parent Product', 'twentyseventeen' ),
        'all_items'           => __( 'All Products', 'twentyseventeen' ),
        'view_item'           => __( 'View Product', 'twentyseventeen' ),
        'add_new_item'        => __( 'Add New Product', 'twentyseventeen' ),
        'add_new'             => __( 'Add New', 'twentyseventeen' ),
        'edit_item'           => __( 'Edit Product', 'twentyseventeen' ),
        'update_item'         => __( 'Update Product', 'twentyseventeen' ),
        'search_items'        => __( 'Search Product', 'twentyseventeen' ),
        'not_found'           => __( 'Not Found', 'twentyseventeen' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentyseventeen' ),

// Set other options for Custom Post Type

    $args = array(
        //'label'               => __( 'products', 'twentyseventeen' ),
        'description'         => __( 'Products and reviews', 'twentyseventeen' ),
        'labels'              => $labels,
        // Features this CPT supports in Post Editor
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        // You can associate this CPT with a taxonomy or custom taxonomy. 
        'taxonomies'          => array( 'category', 'tag' ),
        /* A hierarchical CPT is like Pages and can have
        * Parent and child items. A non-hierarchical CPT
        * is like Posts.
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
        'show_in_rest' => true,


    // Registering your Custom Post Type
    register_post_type( 'products', $args );


/* Hook into the 'init' action so that the function
* Containing our post type registration is not 
* unnecessarily executed. 

add_action( 'init', 'custom_post_type', 0 );

I have created a category called "Shop" and I want these CPT "products" to appear in my "Shop" category so that when I visit a list of them is displayed.

I have added the category function to taxonomies and can select the shop category when creating a new product. However, the permalink is always only

Whenever I create a new custom product post, I fill out the description, add the custom fields and title, select the shop category … and everything seems to be fine until I press "publish". then a "Permalink" drop down section appears in the editor, and I am told that I can see the product at … if I have never selected a product category … and one Product category does not even exist / never existed !!!

What gives?

When I visit there is nothing to see.

And when I visit, I will be redirected to (which, by the way, is well displayed).

Any idea where this ghost category called "products" comes from?

Why doesn't the publisher respect my desire to place a product in the "Shop" category? And instead place it in its own category "Products" (which does not even exist / was never created in the WordPress administrator dashboard).

The only change I've made to any PHP code is to add the single function in the functions.php file of my theme.

I even updated / deleted the permalink settings by saving them again in the custom permalink area of ​​the dashboard.

Thanks a lot.

EDIT: I think I may miss the "rewrite" argument? As explained here:

(bool|array) Triggers the handling of rewrites for this post type. To prevent rewrite, set to false. Defaults to true, using $post_type as slug. To specify rewrite rules, an array can be passed with any of these keys:

woocommerce – product_id is null when retrieving product data in functions.php

I'm creating a custom function to get all the data of the product into one category
in the functions.php

function get_products()
  $cat_id = $_POST('category');
  $args = array(
  'post_type'             => 'product',
  'post_status'           => 'publish',
  'ignore_sticky_posts'   => 1,
  'posts_per_page'        => '12',
  'tax_query'             => array(
    'taxonomy'      => 'product_cat',
    'field' => 'term_id', //This is optional, as it defaults to 'term_id'
    'terms'         => $cat_id,
    'operator'      => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
    'taxonomy'      => 'product_visibility',
    'field'         => 'slug',
    'terms'         => 'exclude-from-catalog', // Possibly 'exclude-from-search' too
    'operator'      => 'NOT IN'
$wc_query = new WP_Query($args);

if ($wc_query->have_posts()) : 
  while ($wc_query->have_posts()) :
//echo json_encode($products);


The result is zero for each ID

What's the mistake?

Actions – How do I manage arrays of custom functions stored in functions.php?

In functions.php I made the following code:

add_action( 'listofnames', 'SomeNames' );

function SomeNames(){

$names=array( "john","edgar","miles");
return $names;


It should return an array that I want to manipulate with, but if I try index.php it will go wrong. Obviously it doesn't work like this:

foreach (do_action('listofnames') as $n){

echo $n;

Can someone help me do this?

Non riesco ad includesere in nessun modo il css nel mio tema usando functions.php

I cannot integrate CSS with functions.php in my theme in any way

I tried to include CSS via the link tag, but it only loads on the first page. Then when I open other pages (for example the sample page), I don't load a style. How can I do that?

This is the code:

Function theme_styles ()
wp_enqueue_style (& # 39; style & # 39 ;, get_template_directory_uri (). & # 39; /style.css&#39;);
wp_enqueue_style (& # 39; bootstrap & # 39 ;, get_template_directory_uri (). & # 39; /css/bootstrap.min.css&#39;);
wp_enqueue_style (& # 39; font & # 39 ;, get_template_directory_uri (). & # 39; /css/font-awesome.min.css&#39;);
add_action (& # 39; wp_enqueue_scripts & # 39 ;, & # 39; theme_styles & # 39;);

Rotate prefix for external domain links with functions.php?

How to switch from multiple prefixes for all links to an external domain

Our prefixes:


The final URL looks like this: // …

There are only a few plugins in WordPress that insert the prefix, but only allow 1 prefix.
How do you achieve a simple rotation of the order between these 3 prefixes with functions.php?