AMP – Change rel=”canonical” from functions.php [closed]

In general you can deregister the action’s callback, after it’s been registered and then register your own before it’s invoked with do_action( ‘…’ ). Here’s an example: // Add your own with later priority, e.g. 11 or wrap it in another later hook: add_action( ‘amp_post_template_head’, ‘wpse_amp_post_template_add_canonical’, 11 ); function wpse_amp_post_template_add_canonical( $amp_template ) { // Remove … Read more

Function to alphabetically sort custom post types creating duplicates

‘orderby’ => ‘name’ sorts by slug – not title; therefore, the title Imancorp Foundation which has this permalink http://www.alianzafpdual.es/las-empresas/fundacion-imancorp-foundation/ breaks the list. https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters try and use instead ‘orderby’ => ‘title’

How can I modify the element on all pages?

The <header> elements are usually echoed directly by the theme. So without any hook or filter to change them. In that case, there is no way to change those elements with a function. Check your theme. You could, of course, use javascript to place you attributes, but that would happen on the user end. Search … Read more

Shortcode parse error – wrong syntax

UPDATE Seems like the shortcode you’re trying to use is not well coded. If they use it somewhere in the templates alone like echo do_shortcode(‘[share]’); it doesn’t really matter since the ‘[share]’ is the only content passed to do_shortcode(). In your case you’re trying to reuse the shortcode in a context where it’s placed among … Read more

Pass variable from action back to template

The difference between add_action() and add_filter() is semantic not technical, except that a filter expects a returned value and an action does/will not. The question is whether contact_form_send_email() needs to be called-at /hooked-to init. If not, you can define your filter in the template with apply_filters(), and then hook to it to run your function … Read more

Should I store functions in separate folder?

Generally I keep the more back-end functions in functions.php and then use require() to call partials that contain groups of functions that are similar such as how the Underscores started theme written by the WordPress people does it. But putting every single function in a separate file is a bit excessive.

Send email to admin user when custom post type is created

If you want to send an email on first publish and on updates, you can avoid many extra checks by using {status}_{post type} action hook. Put the code below into the current theme’s functions.php: add_action( ‘publish_task’, ‘wpse_admin_email’, 10, 2 ); function wpse_admin_email( $post_id, $post ) { // prepare and send email code goes here… } … Read more

Use /prefix/postname as a slug in post_name?

Well it turns out you can’t use a slash (“https://wordpress.stackexchange.com/”) in the slug but I found a solution from How to set permalink structure via functions.php, set the permalink structure in your theme’s functions.php file add_action( ‘init’, function() { global $wp_rewrite; $wp_rewrite->set_permalink_structure( ‘/episode/%postname%/’ ); } ); It will add /episode/ before the post slug