Add custom path to url to specific pages

If you want to change the permalink structure for all Pages (i.e. posts of the page type), you can use the WP_Rewrite::$page_structure property like so: add_action( ‘init’, ‘wpse_382911′ ); function wpse_382911() { global $wp_rewrite; $wp_rewrite->page_structure=”home/%pagename%”; } Don’t forget to flush the rewrite rules — just visit the permalink settings admin page (wp-admin → Settings → … Read more

Slashes stripped in ACF

Until this gets fixed, the only workaround I can see is to intercept the $_POST data and add extra slashes prior to ACF stripping them: /** * @link http://wordpress.stackexchange.com/q/143555/1685 */ function wpse_143555_acf_add_slashes() { if ( ! empty( $_POST[‘fields’] ) ) { foreach ( $_POST[‘fields’] as $k => $v ) { if ( ! is_array( $v … Read more

How to have a custom URI path for specific page template

You need to add a rewrite rule to WordPress. There are several options to do it depending on your exact needs. Maybe the most general is using add_rewrite_tag() and add_rewrite_rule(): add_action( ‘init’, ‘cyb_rewrite_rules’ ); function cyb_rewrite_rules() { add_rewrite_tag( ‘%variable1%’, ‘([^&]+)’ ); add_rewrite_tag( ‘%variable2%’, ‘([^&]+)’ ); add_rewrite_rule( ^system/([^/]*)/([^/]*)/?’, ‘index.php?pagename=$matches[1]&variable1=$matches[2]&variable2=$matches[3]’, ‘top’ ); } Now, if the URL … Read more

How to get path or root of plugin folder, not file or dir?

How about just define a constant that stores the plugin’s root path? Define path constant For calling numerous files, it is sometimes convenient to define a constant: define( ‘MY_PLUGIN_PATH’, plugin_dir_path( __FILE__ ) ); include( MY_PLUGIN_PATH . ‘includes/admin-page.php’); include( MY_PLUGIN_PATH . ‘includes/classes.php’); // etc. — See https://developer.wordpress.org/reference/functions/plugin_dir_path/#comment-491 So in your main plugin file: define( ‘MY_PLUGIN_PATH’, plugin_dir_path( … Read more

wp_enqueue_script not loading my custom js file

You need to reference your WordPress template directory when you register the script. Change this: wp_enqueue_script(‘my_javascript_file’, ‘/javascripts/app.js’, array(‘jquery’)); …to this: wp_enqueue_script(‘my_javascript_file’, get_template_directory_uri() . ‘/javascripts/app.js’, array(‘jquery’)); Codex reference: get_template_directory_uri()

hijacking home_url for root relative paths

You need to set the WP_HOME and WP_SITEURL in wp-config.php in a smarter way. Like this: <?php define(‘WP_HOME’, ‘http://’ . $_SERVER[‘HTTP_HOST’]); // add the next line if you have a subdirectory install define(‘WP_SITEURL’, WP_HOME . ‘/path/to/wordpress’); This will solve your your issues with site URLs as they will be set dynamically on based on whatever … Read more