How to access the WordPress DB from a plugin file

If you plan to share/sell your plugin I strongly suggest don’t load your plugin directly. That because to load WordPress you need to load the bootstrap file, that is /wp-load.php so, you should put in your embed-video.php something like: require ‘/wordpress/path/wp-load.php’; Do you notice the problem here? The /wordpress/path/ part is different for user to … Read more

Add # to submenu URLs automatically

This ended up doing the trick. function auto_hashtag( $menu_item ) { if ( ! is_admin() && $menu_item->post_parent > 0) { // url $url = $menu_item->url; $menu_item->url = preg_replace(‘!/([^/]+)/$!’, “/#\\1”, $url); } return $menu_item; } add_filter( ‘wp_setup_nav_menu_item’, ‘auto_hashtag’ );

Change url of posts with keywords

I guess you are using custom post type with custom category is it?If so, then I suggest using this plugin: http://wordpress.org/plugins/custom-post-type-permalinks/ Set it up, go to Settings -> permalink settings and there will be an additional settings called “Permalink Settings for Custom Post types”. Enter something like : /%item%/%postname% If you are not using a … Read more

Rewriting a date hierarchy into a ‘yyyy-mm-dd’ slug

Internal rewrite rules have to point to index.php and set the proper query vars for WordPress to be able to load the requested object: add_rewrite_rule( ‘magazine/(\d{4})/(\d{2})/(\d{2})/?’, ‘index.php?issue=$matches[1]-$matches[2]-$matches[3]’, ‘top’ ); That should get incoming requests to resolve correctly, however, that’s only half the task. If you call the_permalink for your posts, you’ll still get the format … Read more

Adding more onto an esc_url [closed]

To concatenate strings, PHP uses the concatenation operator .. Thus, to append a string to the current user link, you can use bp_core_get_userlink( get_the_author_meta( ‘ID’ ), false, true ) . ‘/posts/’ Note that I’ve removed the first part of the assignment from the $no_anchor and $just_link parameters, as the values should be passed, and not … Read more