Skip to content

Instantly share code, notes, and snippets.

@javi-g
javi-g / code-to-add-to-functions.php
Last active May 16, 2024 17:26
Customize message after a WP post is published
<?php // don't add this again to the end of functions.php :-)
function javi_enqueue_custom_gutenberg_script() {
$script_path = get_template_directory() . '/custom-gutenberg.js'; // this is the path into the theme
$script_url = get_template_directory_uri() . '/custom-gutenberg.js'; // same path as above
if (file_exists($script_path)) {
wp_enqueue_script(
'custom-gutenberg',
$script_url,
array('wp-data', 'wp-dom-ready', 'wp-edit-post'),
// Tras rewrite en WooCommerce, Yoast seguía devolviendo canonicals antiguos
// Código para prevenirlo (usadlo con cuidado y comprobar los canonicals posteriormente)
function usm_filter_yoastcanonical( $canonical ) {
if (is_product()) { // sólo alteramos el canonical de los productos, no el resto
$canonical = get_permalink();
}
return $canonical;
}
add_filter( 'wpseo_canonical', 'usm_filter_yoastcanonical' );