https://github.com/mazeyqian/mazey-wordpress-utils
WordPress utilities.
https://github.com/mazeyqian/mazey-wordpress-utils
npm utilities wordpress
Last synced: about 1 year ago
JSON representation
WordPress utilities.
- Host: GitHub
- URL: https://github.com/mazeyqian/mazey-wordpress-utils
- Owner: mazeyqian
- License: mit
- Created: 2018-01-20T06:27:37.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2025-03-08T14:08:30.000Z (over 1 year ago)
- Last Synced: 2025-03-30T04:31:56.665Z (over 1 year ago)
- Topics: npm, utilities, wordpress
- Language: JavaScript
- Homepage:
- Size: 696 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mazey WordPress Utils
[![NPM version][npm-image]][npm-url]
[![l][l-image]][l-url]
[npm-image]: https://img.shields.io/npm/v/mazey-wordpress-utils
[npm-url]: https://npmjs.org/package/mazey-wordpress-utils
[l-image]: https://img.shields.io/npm/l/mazey-wordpress-utils
[l-url]: https://github.com/mazeyqian/mazey-wordpress-utils
WordPress utilities.
## Install
You can get mazey-wordpress-utils via [npm](https://www.npmjs.com/package/mazey-wordpress-utils).
```bash
npm install mazey-wordpress-utils --save
```
## Usage
### hideSidebar
Hide the sidebar on the webpage.
Example:
```javascript
hideSidebar({
urlContainList: ['hide_sidebar', 'no_sidebar'],
primarySelector: '#main-content',
secondarySelector: '#sidebar'
});
```
### hideHeaderInTOC
Hide the header when it meets one of these two conditions:
- Use WordPress Plugin [Easy Table of Contents](https://wordpress.org/plugins/easy-table-of-contents/) and open it in this page.
- The page's URL is matched with one of the `urlContainList`.
Example:
```javascript
hideHeaderInTOC({
urlContainList: ['hide_header_in_toc', 'no_header_in_toc'],
headerSelector: '.site-header'
});
```
### isIncludeInUrl
Check if the current URL includes a specified string.
Example:
```javascript
isIncludeInUrl({
urlContainString: 'example'
});
```
### setImgWidthHeight
Set the width and height of an image based on the parameters specified in the image's URL.
Use jQuery to select all `img` elements on the page and then checks each image's `src` attribute for `width` and `height` parameters. If these parameters are found, the function sets the image's width and height accordingly.
The width and height parameters in the URL should be in the format `width=` and `height=`, where `` is a number and `` is a CSS unit like `px`, `rem`, or `vw`.
Example 1:
For an image with the URL `
`, the function will execute `window.jQuery('img').width('400px')` and `window.jQuery('img').height('200px')`.
Example 2:
For an image with the URL `
`, the function will execute `window.jQuery('img').width('400rem')` and `window.jQuery('img').height('20vw')`.
## Contributing
```bash
# dev
npm run dev
# build
npm run build
```