Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Mohan Dere mohandere

🎯
Focusing
Block or report user

Report or block mohandere

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mohandere
mohandere / yoast-seo-sitemap.php
Last active Jun 25, 2019
Wordpress yoast seo plugin, generate custom sitemap for custom URLS
View yoast-seo-sitemap.php
<?php
/**
* Create a new custom yoast seo sitemap
*/
add_filter( 'wpseo_sitemap_index', 'ex_add_sitemap_custom_items' );
add_action( 'init', 'init_wpseo_do_sitemap_actions' );
// Add custom index
@mohandere
mohandere / get-isotope-items.php
Last active May 17, 2019
jQuery isotope plugin for wordpress posts filtering by category with pagination.
View get-isotope-items.php
<?php
function get_isotope_item( $query_args = array() ){
$defaults = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
);
@mohandere
mohandere / child.js
Last active May 16, 2019
Iframe height issue - make iframe height dynamic based on content inside
View child.js
(function(){
'use-strict';
/**
* Iframe to Parent window communication
* sample iframe- <iframe id="guestFrame" name="guestFrame" src="http://other-domain.com/">
* </iframe>
* Uses https://ternarylabs.github.io/porthole/
* Uses https://marcj.github.io/css-element-queries/
View hoc-caveat-02-fix.js
import hoistNonReactStatic from 'hoist-non-react-statics';
const withSearch = (WrappedComponent) => {
class WithSearch extends React.Component {/*...*/}
hoistNonReactStatic(EithSearch, WrappedComponent);
return WithSearch;
}
// Define a static method
ProductsList.staticMethod = function() {/*...*/}
View hoc-caveat-01.js
render() {
// A new version of ProductsListWithSearch is created on every render
const ProductsListWithSearch = withSearch(ProductsList);
// That causes the entire subtree to unmount/remount each time!
return <ProductsListWithSearch />;
}
@mohandere
mohandere / hoc-withSearch.js
Last active May 12, 2019
Higher-Order Components
View hoc-withSearch.js
const withSearch = WrappedComponent => {
class WithSearch extends React.Component {
state = {
searchTerm: ""
};
handleSearch = event => {
this.setState({ searchTerm: event.target.value });
};
render() {
@mohandere
mohandere / hoc-ProductsList.js
Last active May 12, 2019
Higher-Order Component
View hoc-ProductsList.js
const ProductsList = (props) => {
let { data: products } = props;
return (
<div>
<div>
<div>
<h2>Products</h2>
</div>
</div>
<div>
@mohandere
mohandere / hoc-ProductsWithSearch.js
Last active May 12, 2019
Higher-Order Component
View hoc-ProductsWithSearch.js
import products from './products.json'
class ProductsListWithSearch extends React.PureComponent {
state = {
searchTerm: ''
}
handleSearch = event => {
this.setState({ searchTerm: event.target.value })
}
render() {
View hoc-withSearch-full-example.js
const ProductCard = props => {
return (
<div>
<hr />
<p>
<b>Title:</b> {props.title}
</p>
<p>
<b>Style:</b> {props.style}
</p>
View hoc-ProductCard.js
const ProductCard = props => {
return (
<div className="product">
<p>
<b>Title:</b> {props.title}
</p>
<p>
<b>Style:</b> {props.style}
</p>
<p>
You can’t perform that action at this time.