Including CSS and JS on Admin Screen of Custom Theme Options

If you create an admin theme plugin from the Codex steps, you will notice it says not to insert stylesheets as per above – although the above will work. If you place the following inside your admin theme file, it will serve the same purpose, but uses the wp_enqueue_styles approach: function add_admin_theme_styles() { wp_register_style($handle=”mytheme-theme-admin-styles”, $src … Read more

How to control initial wp_head() output?

Here is the current list of actions that is currently hooked by default to wp_head Reposted here to avoid unnecessary opening multiple browser windows add_action( ‘wp_head’, ‘_wp_render_title_tag’, 1 ); add_action( ‘wp_head’, ‘wp_enqueue_scripts’, 1 ); add_action( ‘wp_head’, ‘feed_links’, 2 ); add_action( ‘wp_head’, ‘feed_links_extra’, 3 ); add_action( ‘wp_head’, ‘rsd_link’ ); add_action( ‘wp_head’, ‘wlwmanifest_link’ ); add_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, … Read more

How Do I Programmatically Force Custom Permalinks with My Theme?

To fully enable permalinks, you also need to ensure that .htaccess is also created. To do that, you need to set an option and flush the rules with a Boolean. global $wp_rewrite; //Write the rule $wp_rewrite->set_permalink_structure(‘/%postname%/’); //Set the option update_option( “rewrite_rules”, FALSE ); //Flush the rules and tell it to write htaccess $wp_rewrite->flush_rules( true ); … Read more

get_attached_media() returns empty array if media file already used by another post

I ran into this problem and ended up creating a basic function to extract the “attached” media by URL from the body of the post (in my case a post of type document, but it should work with any kind of post): function get_first_link_url($post_id) { $content = get_post_field(‘post_content’, $post_id); if ($content == null) { return … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)