Loading...

Follow Code And Me - WordPress Code Snippet Repository on Feedspot

Continue with Google
Continue with Facebook
or

Valid

Adding the following snippet to your theme’s functions.php file, you will be able to make accessible menu editor.

$ Role_object  = get_role (  'editor'  ) ;
$ role_object -> add_cap (  'edit_theme_options'  ) ;

Snippet Source/Credit: Webundso

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Using the following snippet, you will be able to simulate a view of a page with JavaScript onclick.

<input id="submit" onclick="trackpage('/kontaktudfyldt/')" type="submit" value="<?php _e('Send Email', 'framework') ?>" />
 <script type="text/javascript">
 // <![CDATA[
 var readytosubmit = false;
 function trackpage (track)
 {
 _gaq.push(['_trackPageview',track]);
 readytosubmit = !readytosubmit;
 setTimeout(clicksubmit(), 100)}
 function clicksubmit()
 {
 document.getElementById("submit").click();
 }
 // ]]>
 </script>

Snippet Source/Credit: Reiffs.dk

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Using the following snippet, you will be able to change role access to menu and widgets in WordPress.

<?php
// get the the role object
$role_object = get_role('editor');
// add $cap capability to this role object
$role_object->add_cap('edit_theme_options');
?>

Snippet Source/Credit: WP-Snippets.com

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Using the following snippet, you will be able to have custom menus for different category/page/post.

<?php
// add the following to wp theme function.php
	register_nav_menus( array(
		'primary-menu' => 'main menu',
                'marketing-menu' => 'marketing menu',
                'shopping menu' => 'shopping menu',
		'technology menu' =>  'technology menu',
		'recreation menu' =>  'recreation menu',
	) );
add_action( 'init', 'register_nav_menus' );
?>
<?php
// add following to where you want the menu share, in my case, hearder.php
<?php
			if((has_nav_menu('marketing-menu') and !is_home() and is_category(array(5,6,8,9,10,11,12,13,14))) or (has_nav_menu('marketing-menu') and !is_home() and in_category(array(5,6,8,9,10,11,12,13,14))))  {
					wp_nav_menu(array(
					'theme_location' => 'marketing-menu',
					'container' => '',
					'menu_id' => 'primary-nav',
					'container_class' => 'main-menu',
					'menu_class' => 'nav'
				 ));
			}
			else(has_nav_menu('primary-menu')){
				 wp_nav_menu(array(
					'theme_location' => 'primary-menu',
					'container' => '',
					'menu_id' => 'primary-nav',
					'container_class' => 'main-menu',
					'menu_class' => 'nav'
				 ));
?>

Snippet Source/Credit: WordPress Code 1, 2, 3, 4

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

The following snippet display the Twitter followers image list.

<?php
//replace $options['twitter'] with the twitter Username you want to use.
?>
		<?php
		$xmlfollowersUrl = 'http://api.twitter.com/1/statuses/followers/'.$options['twitter'].'.xml';
		if (file_exists(WP_CONTENT_DIR.'/uploads/twitter_followers.xml')) {
		$data = unserialize(file_get_contents(WP_CONTENT_DIR.'/uploads/twitter_followers.xml'));
			if ($data['timestamp'] > time() - 120 * 60) {
			$twitter_followers = $data['twitter_result'];
			}
		}
if (!$twitter_followers) { // cache doesn't exist or is older than 10 mins
    $twitter_followers = file_get_contents($xmlfollowersUrl); // or whatever your API call is
    $data = array ('twitter_followers' => $twitter_followers, 'timestamp' => time());
    file_put_contents(WP_CONTENT_DIR.'/uploads/twitter_followers.xml', serialize($data));
}
		$dom = new DOMDocument;
		$s = simplexml_load_string($twitter_followers);
		$count = 0;
		echo '<ul >';
		foreach($s->user as $follower):
			if(++$count > 50){
				break;
				}
			echo '<li><a  href="http://www.twitter.com/'.$follower->screen_name.'"><img width="32" height="32" src="'.$follower->profile_image_url.'" alt="'.$follower->name.'" title="'.$follower->name.': '.$follower->status->text.'"/></a></li>';
		endforeach;
		echo '</ul>';
		?>

Snippet Source/Credit: Snipplr

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Adding the following snippet will let you make a subdirectory accessible with WordPress in root.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(thefoldername).*$ [NC]
RewriteRule . - [L]
</IfModule>

Snippet Source/Credit: DreamHost Wiki

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

The following snippet will let you deregister all in one event calendar in WordPress.

// clean up unwanted JS scripts
function my_print_scripts(){
   if ( !is_admin() ) {
      wp_deregister_script('jquery');
      wp_deregister_script('ai1ec_requirejs');
   }
}
add_action('wp_print_scripts', 'my_print_scripts');
// clean up unwanted CSS
function my_print_css() {
   if ( !is_admin() ) {
      wp_deregister_style('ai1ec-general');
      wp_deregister_style('ai1ec-event');
      wp_deregister_style('ai1ec-calendar');
   }
}
add_action('wp_print_styles', 'my_print_css');

Snippet Source/Credit: Ditscheri.com

Read Full Article
  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview